Artificial Intelligence Nanodegree

Computer Vision Capstone

Project: Facial Keypoint Detection


Welcome to the final Computer Vision project in the Artificial Intelligence Nanodegree program!

In this project, you’ll combine your knowledge of computer vision techniques and deep learning to build and end-to-end facial keypoint recognition system! Facial keypoints include points around the eyes, nose, and mouth on any face and are used in many applications, from facial tracking to emotion recognition.

There are three main parts to this project:

Part 1 : Investigating OpenCV, pre-processing, and face detection

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!


*Here's what you need to know to complete the project:

  1. In this notebook, some template code has already been provided for you, and you will need to implement additional functionality to successfully complete this project. You will not need to modify the included code beyond what is requested.

    a. Sections that begin with '(IMPLEMENTATION)' in the header indicate that the following block of code will require additional functionality which you must provide. Instructions will be provided for each section, and the specifics of the implementation are marked in the code block with a 'TODO' statement. Please be sure to read the instructions carefully!

  1. In addition to implementing code, there will be questions that you must answer which relate to the project and your implementation.

    a. Each section where you will answer a question is preceded by a 'Question X' header.

    b. Carefully read each question and provide thorough answers in the following text boxes that begin with 'Answer:'.

Note: Code and Markdown cells can be executed using the Shift + Enter keyboard shortcut. Markdown cells can be edited by double-clicking the cell to enter edit mode.

The rubric contains optional suggestions for enhancing the project beyond the minimum requirements. If you decide to pursue the "(Optional)" sections, you should include the code in this IPython notebook.

Your project submission will be evaluated based on your answers to each of the questions and the code implementations you provide.

Steps to Complete the Project

Each part of the notebook is further broken down into separate steps. Feel free to use the links below to navigate the notebook.

In this project you will get to explore a few of the many computer vision algorithms built into the OpenCV library. This expansive computer vision library is now almost 20 years old and still growing!

The project itself is broken down into three large parts, then even further into separate steps. Make sure to read through each step, and complete any sections that begin with '(IMPLEMENTATION)' in the header; these implementation sections may contain multiple TODOs that will be marked in code. For convenience, we provide links to each of these steps below.

Part 1 : Investigating OpenCV, pre-processing, and face detection

  • Step 0: Detect Faces Using a Haar Cascade Classifier
  • Step 1: Add Eye Detection
  • Step 2: De-noise an Image for Better Face Detection
  • Step 3: Blur an Image and Perform Edge Detection
  • Step 4: Automatically Hide the Identity of an Individual

Part 2 : Training a Convolutional Neural Network (CNN) to detect facial keypoints

  • Step 5: Create a CNN to Recognize Facial Keypoints
  • Step 6: Compile and Train the Model
  • Step 7: Visualize the Loss and Answer Questions

Part 3 : Putting parts 1 and 2 together to identify facial keypoints on any image!

  • Step 8: Build a Robust Facial Keypoints Detector (Complete the CV Pipeline)

Step 0: Detect Faces Using a Haar Cascade Classifier

Have you ever wondered how Facebook automatically tags images with your friends' faces? Or how high-end cameras automatically find and focus on a certain person's face? Applications like these depend heavily on the machine learning task known as face detection - which is the task of automatically finding faces in images containing people.

At its root face detection is a classification problem - that is a problem of distinguishing between distinct classes of things. With face detection these distinct classes are 1) images of human faces and 2) everything else.

We use OpenCV's implementation of Haar feature-based cascade classifiers to detect human faces in images. OpenCV provides many pre-trained face detectors, stored as XML files on github. We have downloaded one of these detectors and stored it in the detector_architectures directory.

Import Resources

In the next python cell, we load in the required libraries for this section of the project.

In [1]:
# Import required libraries for this section

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import math
import cv2                     # OpenCV library for computer vision
from PIL import Image
import time 

Next, we load in and display a test image for performing face detection.

Note: by default OpenCV assumes the ordering of our image's color channels are Blue, then Green, then Red. This is slightly out of order with most image types we'll use in these experiments, whose color channels are ordered Red, then Green, then Blue. In order to switch the Blue and Red channels of our test image around we will use OpenCV's cvtColor function, which you can read more about by checking out some of its documentation located here. This is a general utility function that can do other transformations too like converting a color image to grayscale, and transforming a standard color image to HSV color space.

In [2]:
# Load in color image for face detection
image = cv2.imread('images/test_image_1.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot our image using subplots to specify a size and title
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[2]:
<matplotlib.image.AxesImage at 0x7f1693faf5c0>

There are a lot of people - and faces - in this picture. 13 faces to be exact! In the next code cell, we demonstrate how to use a Haar Cascade classifier to detect all the faces in this test image.

This face detector uses information about patterns of intensity in an image to reliably detect faces under varying light conditions. So, to use this face detector, we'll first convert the image from color to grayscale.

Then, we load in the fully trained architecture of the face detector -- found in the file haarcascade_frontalface_default.xml - and use it on our image to find faces!

To learn more about the parameters of the detector see this post.

In [3]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[3]:
<matplotlib.image.AxesImage at 0x7f1693f922b0>

In the above code, faces is a numpy array of detected faces, where each row corresponds to a detected face. Each detected face is a 1D array with four entries that specifies the bounding box of the detected face. The first two entries in the array (extracted in the above code as x and y) specify the horizontal and vertical positions of the top left corner of the bounding box. The last two entries in the array (extracted here as w and h) specify the width and height of the box.


Step 1: Add Eye Detections

There are other pre-trained detectors available that use a Haar Cascade Classifier - including full human body detectors, license plate detectors, and more. A full list of the pre-trained architectures can be found here.

To test your eye detector, we'll first read in a new test image with just a single face.

In [4]:
# Load in color image for face detection
image = cv2.imread('images/james.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Plot the RGB image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)
Out[4]:
<matplotlib.image.AxesImage at 0x7f1693f3b5f8>

Notice that even though the image is a black and white image, we have read it in as a color image and so it will still need to be converted to grayscale in order to perform the most accurate face detection.

So, the next steps will be to convert this image to grayscale, then load OpenCV's face detector and run it with parameters that detect this face accurately.

In [5]:
# Convert the RGB  image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.25, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detection')
ax1.imshow(image_with_detections)
Number of faces detected: 1
Out[5]:
<matplotlib.image.AxesImage at 0x7f1693ee45f8>

(IMPLEMENTATION) Add an eye detector to the current face detection setup.

A Haar-cascade eye detector can be included in the same way that the face detector was and, in this first task, it will be your job to do just this.

To set up an eye detector, use the stored parameters of the eye cascade detector, called haarcascade_eye.xml, located in the detector_architectures subdirectory. In the next code cell, create your eye detector and store its detections.

A few notes before you get started:

First, make sure to give your loaded eye detector the variable name

eye_cascade

and give the list of eye regions you detect the variable name

eyes

Second, since we've already run the face detector over this image, you should only search for eyes within the rectangular face regions detected in faces. This will minimize false detections.

Lastly, once you've run your eye detector over the facial detection region, you should display the RGB image with both the face detection boxes (in red) and your eye detections (in green) to verify that everything works as expected.

In [6]:
# Make a copy of the original image to plot rectangle detections
image_with_detections = np.copy(image)   

# Loop over the detections and draw their corresponding face detection boxes
for (x,y,w,h) in faces:
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h),(255,0,0), 3)  
    
# Do not change the code above this comment!
    
## TODO: Add eye detection, using haarcascade_eye.xml, to the current face detector algorithm
eye_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_eye.xml')

# Detect eyes in image
#pick the largest bounding box
area = 0
start, end = (0,0),(0,0)
for (x,y,w,h) in faces:
    a = w * h
    if (area < a):
        area = a
        start, end = (x,y), (x+w,y+h)
    
    
#crop_face = gray[start[1]:end[1], start[0]:end[0]].copy()
mask = np.zeros(gray.shape,np.uint8)
mask[start[1]:end[1], start[0]:end[0]] = gray[start[1]:end[1], start[0]:end[0]]
# NOTE: its img[y: y + h, x: x + w] and *not* img[x: x + w, y: y + h]
plt.imshow(mask, cmap='gray')
eyes = eye_cascade.detectMultiScale(mask, 1.20, 3)

# Print the number of faces detected in the image
print('Number of eyes detected:', len(eyes))
## TODO: Loop over the eye detections and draw their corresponding boxes in green on image_with_detections
for (x,y,w,h) in eyes:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (0,255,0), 3)

# Plot the image with both faces and eyes detected
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face and Eye Detection')
ax1.imshow(image_with_detections)
Number of eyes detected: 2
Out[6]:
<matplotlib.image.AxesImage at 0x7f1693ec26d8>

(Optional) Add face and eye detection to your laptop camera

It's time to kick it up a notch, and add face and eye detection to your laptop's camera! Afterwards, you'll be able to show off your creation like in the gif shown below - made with a completed version of the code!

Notice that not all of the detections here are perfect - and your result need not be perfect either. You should spend a small amount of time tuning the parameters of your detectors to get reasonable results, but don't hold out for perfection. If we wanted perfection we'd need to spend a ton of time tuning the parameters of each detector, cleaning up the input image frames, etc. You can think of this as more of a rapid prototype.

The next cell contains code for a wrapper function called laptop_camera_face_eye_detector that, when called, will activate your laptop's camera. You will place the relevant face and eye detection code in this wrapper function to implement face/eye detection and mark those detections on each image frame that your camera captures.

Before adding anything to the function, you can run it to get an idea of how it works - a small window should pop up showing you the live feed from your camera; you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [2]:
### Add face and eye detection to this laptop camera function 
# Make sure to draw out all faces/eyes found in each frame on the shown video feed

import cv2
import time 

# wrapper function for face/eye detection with your laptop camera
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep the video stream open
    while rval:
        # Plot the image from camera with all the face and eye detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            # Make sure window closes on OSx
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
In [ ]:
# Call the laptop camera face/eye detector function above
laptop_camera_go()

Step 2: De-noise an Image for Better Face Detection

Image quality is an important aspect of any computer vision task. Typically, when creating a set of images to train a deep learning network, significant care is taken to ensure that training images are free of visual noise or artifacts that hinder object detection. While computer vision algorithms - like a face detector - are typically trained on 'nice' data such as this, new test data doesn't always look so nice!

When applying a trained computer vision algorithm to a new piece of test data one often cleans it up first before feeding it in. This sort of cleaning - referred to as pre-processing - can include a number of cleaning phases like blurring, de-noising, color transformations, etc., and many of these tasks can be accomplished using OpenCV.

In this short subsection we explore OpenCV's noise-removal functionality to see how we can clean up a noisy image, which we then feed into our trained face detector.

Create a noisy image to work with

In the next cell, we create an artificial noisy version of the previous multi-face image. This is a little exaggerated - we don't typically get images that are this noisy - but image noise, or 'grainy-ness' in a digitial image - is a fairly common phenomenon.

In [7]:
# Load in the multi-face test image again
image = cv2.imread('images/test_image_1.jpg')

# Convert the image copy to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Make an array copy of this image
image_with_noise = np.asarray(image)

# Create noise - here we add noise sampled randomly from a Gaussian distribution: a common model for noise
noise_level = 40
noise = np.random.randn(image.shape[0],image.shape[1],image.shape[2])*noise_level

# Add this noise to the array image copy
image_with_noise = image_with_noise + noise

# Convert back to uint8 format
image_with_noise = np.asarray([np.uint8(np.clip(i,0,255)) for i in image_with_noise])

# Plot our noisy image!
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image')
ax1.imshow(image_with_noise)
Out[7]:
<matplotlib.image.AxesImage at 0x7f1693efdf28>

In the context of face detection, the problem with an image like this is that - due to noise - we may miss some faces or get false detections.

In the next cell we apply the same trained OpenCV detector with the same settings as before, to see what sort of detections we get.

In [8]:
# Convert the RGB  image to grayscale
gray_noise = cv2.cvtColor(image_with_noise, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_noise, 4, 6)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_with_noise)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Noisy Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 11
Out[8]:
<matplotlib.image.AxesImage at 0x7f164e533f28>

With this added noise we now miss one of the faces!

(IMPLEMENTATION) De-noise this image for better face detection

Time to get your hands dirty: using OpenCV's built in color image de-noising functionality called fastNlMeansDenoisingColored - de-noise this image enough so that all the faces in the image are properly detected. Once you have cleaned the image in the next cell, use the cell that follows to run our trained face detector over the cleaned image to check out its detections.

You can find its official documentation here and a useful example here.

Note: you can keep all parameters except photo_render fixed as shown in the second link above. Play around with the value of this parameter - see how it affects the resulting cleaned image.

In [30]:
## TODO: Use OpenCV's built in color image de-noising function to clean up our noisy image!
denoised_image = cv2.fastNlMeansDenoisingColored(image_with_noise,None,9,10,7,21)
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('DeNoised Image')
ax1.imshow(denoised_image)
Out[30]:
<matplotlib.image.AxesImage at 0x7f164c576978>
In [32]:
## TODO: Run the face detector on the de-noised image to improve your detections and display the result
gray_denoise = cv2.cvtColor(denoised_image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray_denoise, 4, 5)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(denoised_image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('DeNoised Image with Face Detections')
ax1.imshow(image_with_detections)
Number of faces detected: 13
Out[32]:
<matplotlib.image.AxesImage at 0x7f164c4ce748>

Step 3: Blur an Image and Perform Edge Detection

Now that we have developed a simple pipeline for detecting faces using OpenCV - let's start playing around with a few fun things we can do with all those detected faces!

Importance of Blur in Edge Detection

Edge detection is a concept that pops up almost everywhere in computer vision applications, as edge-based features (as well as features built on top of edges) are often some of the best features for e.g., object detection and recognition problems.

Edge detection is a dimension reduction technique - by keeping only the edges of an image we get to throw away a lot of non-discriminating information. And typically the most useful kind of edge-detection is one that preserves only the important, global structures (ignoring local structures that aren't very discriminative). So removing local structures / retaining global structures is a crucial pre-processing step to performing edge detection in an image, and blurring can do just that.

Below is an animated gif showing the result of an edge-detected cat taken from Wikipedia, where the image is gradually blurred more and more prior to edge detection. When the animation begins you can't quite make out what it's a picture of, but as the animation evolves and local structures are removed via blurring the cat becomes visible in the edge-detected image.

Edge detection is a convolution performed on the image itself, and you can read about Canny edge detection on this OpenCV documentation page.

Canny edge detection

In the cell below we load in a test image, then apply Canny edge detection on it. The original image is shown on the left panel of the figure, while the edge-detected version of the image is shown on the right. Notice how the result looks very busy - there are too many little details preserved in the image before it is sent to the edge detector. When applied in computer vision applications, edge detection should preserve global structure; doing away with local structures that don't help describe what objects are in the image.

In [33]:
# Load in the image
image = cv2.imread('images/fawzia.jpg')

# Convert to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)  

# Perform Canny edge detection
edges = cv2.Canny(gray,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
Out[33]:
<matplotlib.image.AxesImage at 0x7f164c49e358>

Without first blurring the image, and removing small, local structures, a lot of irrelevant edge content gets picked up and amplified by the detector (as shown in the right panel above).

(IMPLEMENTATION) Blur the image then perform edge detection

In the next cell, you will repeat this experiment - blurring the image first to remove these local structures, so that only the important boudnary details remain in the edge-detected image.

Blur the image by using OpenCV's filter2d functionality - which is discussed in this documentation page - and use an averaging kernel of width equal to 4.

In [34]:
### TODO: Blur the test imageusing OpenCV's filter2d functionality, 
# Use an averaging kernel, and a kernel width equal to 4
kernel = np.ones((4,4),np.float32)/16
dst = cv2.filter2D(gray,-1,kernel)

## TODO: Then perform Canny edge detection and display the output
# Perform Canny edge detection
edges = cv2.Canny(dst,100,200)

# Dilate the image to amplify edges
edges = cv2.dilate(edges, None)

# Plot the RGB and edge-detected image
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(121)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image)

ax2 = fig.add_subplot(122)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Canny Edges')
ax2.imshow(edges, cmap='gray')
 
Out[34]:
<matplotlib.image.AxesImage at 0x7f164c46ad30>

Step 4: Automatically Hide the Identity of an Individual

If you film something like a documentary or reality TV, you must get permission from every individual shown on film before you can show their face, otherwise you need to blur it out - by blurring the face a lot (so much so that even the global structures are obscured)! This is also true for projects like Google's StreetView maps - an enormous collection of mapping images taken from a fleet of Google vehicles. Because it would be impossible for Google to get the permission of every single person accidentally captured in one of these images they blur out everyone's faces, the detected images must automatically blur the identity of detected people. Here's a few examples of folks caught in the camera of a Google street view vehicle.

Read in an image to perform identity detection

Let's try this out for ourselves. Use the face detection pipeline built above and what you know about using the filter2D to blur and image, and use these in tandem to hide the identity of the person in the following image - loaded in and printed in the next cell.

In [35]:
# Load in the image
image = cv2.imread('images/gus.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[35]:
<matplotlib.image.AxesImage at 0x7f164c414588>

(IMPLEMENTATION) Use blurring to hide the identity of an individual in an image

The idea here is to 1) automatically detect the face in this image, and then 2) blur it out! Make sure to adjust the parameters of the averaging blur filter to completely obscure this person's identity.

In [36]:
## TODO: Implement face detection
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.17, 6, 1, (100,100))
#faces = face_cascade.detectMultiScale(gray, 1.3, 5)

# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))

# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image)

# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    

# Display the image with the detections
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Face Detections')
ax1.imshow(image_with_detections)

## TODO: Blur the bounding box around each detected face using an averaging filter and display the result
# Get the bounding box for each detected face
image_copy = np.copy(image)

for (x,y,w,h) in faces:    
    sub_face = image[y:y+h, x:x+w]
    # apply a gaussian blur on this new recangle image
    sub_face = cv2.GaussianBlur(sub_face,(65, 65), 30)
    image_copy[y:y+sub_face.shape[0], x:x+sub_face.shape[1]] = sub_face
    

fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Image with Blurred Face Detections')
ax1.imshow(image_copy)
Number of faces detected: 1
Out[36]:
<matplotlib.image.AxesImage at 0x7f164c3eaf60>

(Optional) Build identity protection into your laptop camera

In this optional task you can add identity protection to your laptop camera, using the previously completed code where you added face detection to your laptop camera - and the task above. You should be able to get reasonable results with little parameter tuning - like the one shown in the gif below.

As with the previous video task, to make this perfect would require significant effort - so don't strive for perfection here, strive for reasonable quality.

The next cell contains code a wrapper function called laptop_camera_identity_hider that - when called - will activate your laptop's camera. You need to place the relevant face detection and blurring code developed above in this function in order to blur faces entering your laptop camera's field of view.

Before adding anything to the function you can call it to get a hang of how it works - a small window will pop up showing you the live feed from your camera, you can press any key to close this window.

Note: Mac users may find that activating this function kills the kernel of their notebook every once in a while. If this happens to you, just restart your notebook's kernel, activate cell(s) containing any crucial import statements, and you'll be good to go!

In [ ]:
### Insert face detection and blurring code into the wrapper below to create an identity protector on your laptop!
import cv2
import time 

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # Exit by pressing any key
            # Destroy windows
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [ ]:
# Run laptop identity hider
laptop_camera_go()

Step 5: Create a CNN to Recognize Facial Keypoints

OpenCV is often used in practice with other machine learning and deep learning libraries to produce interesting results. In this stage of the project you will create your own end-to-end pipeline - employing convolutional networks in keras along with OpenCV - to apply a "selfie" filter to streaming video and images.

You will start by creating and then training a convolutional network that can detect facial keypoints in a small dataset of cropped images of human faces. We then guide you towards OpenCV to expanding your detection algorithm to more general images. What are facial keypoints? Let's take a look at some examples.

Facial keypoints (also called facial landmarks) are the small blue-green dots shown on each of the faces in the image above - there are 15 keypoints marked in each image. They mark important areas of the face - the eyes, corners of the mouth, the nose, etc. Facial keypoints can be used in a variety of machine learning applications from face and emotion recognition to commercial applications like the image filters popularized by Snapchat.

Below we illustrate a filter that, using the results of this section, automatically places sunglasses on people in images (using the facial keypoints to place the glasses correctly on each face). Here, the facial keypoints have been colored lime green for visualization purposes.

Make a facial keypoint detector

But first things first: how can we make a facial keypoint detector? Well, at a high level, notice that facial keypoint detection is a regression problem. A single face corresponds to a set of 15 facial keypoints (a set of 15 corresponding $(x, y)$ coordinates, i.e., an output point). Because our input data are images, we can employ a convolutional neural network to recognize patterns in our images and learn how to identify these keypoint given sets of labeled data.

In order to train a regressor, we need a training set - a set of facial image / facial keypoint pairs to train on. For this we will be using this dataset from Kaggle. We've already downloaded this data and placed it in the data directory. Make sure that you have both the training and test data files. The training dataset contains several thousand $96 \times 96$ grayscale images of cropped human faces, along with each face's 15 corresponding facial keypoints (also called landmarks) that have been placed by hand, and recorded in $(x, y)$ coordinates. This wonderful resource also has a substantial testing set, which we will use in tinkering with our convolutional network.

To load in this data, run the Python cell below - notice we will load in both the training and testing sets.

The load_data function is in the included utils.py file.

In [8]:
from utils import *

# Load training set
X_train, y_train = load_data()
print("X_train.shape == {}".format(X_train.shape))
print("y_train.shape == {}; y_train.min == {:.3f}; y_train.max == {:.3f}".format(
    y_train.shape, y_train.min(), y_train.max()))

# Load testing set
X_test, _ = load_data(test=True)
print("X_test.shape == {}".format(X_test.shape))
X_train.shape == (2140, 96, 96, 1)
y_train.shape == (2140, 30); y_train.min == -0.920; y_train.max == 0.996
X_test.shape == (1783, 96, 96, 1)

The load_data function in utils.py originates from this excellent blog post, which you are strongly encouraged to read. Please take the time now to review this function. Note how the output values - that is, the coordinates of each set of facial landmarks - have been normalized to take on values in the range $[-1, 1]$, while the pixel values of each input point (a facial image) have been normalized to the range $[0,1]$.

Note: the original Kaggle dataset contains some images with several missing keypoints. For simplicity, the load_data function removes those images with missing labels from the dataset. As an optional extension, you are welcome to amend the load_data function to include the incomplete data points.

Visualize the Training Data

Execute the code cell below to visualize a subset of the training data.

In [38]:
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_train[i], y_train[i], ax)

For each training image, there are two landmarks per eyebrow (four total), three per eye (six total), four for the mouth, and one for the tip of the nose.

Review the plot_data function in utils.py to understand how the 30-dimensional training labels in y_train are mapped to facial locations, as this function will prove useful for your pipeline.

(IMPLEMENTATION) Specify the CNN Architecture

In this section, you will specify a neural network for predicting the locations of facial keypoints. Use the code cell below to specify the architecture of your neural network. We have imported some layers that you may find useful for this task, but if you need to use more Keras layers, feel free to import them in the cell.

Your network should accept a $96 \times 96$ grayscale image as input, and it should output a vector with 30 entries, corresponding to the predicted (horizontal and vertical) locations of 15 facial keypoints. If you are not sure where to start, you can find some useful starting architectures in this blog, but you are not permitted to copy any of the architectures that you find online.

In [39]:
# Import deep learning resources from Keras
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, Dropout, GlobalAveragePooling2D
from keras.layers import Flatten, Dense


## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)

model = Sequential()
## TODO: Specify a CNN architecture
# Your model should accept 96x96 pixel graysale images in
# It should have a fully-connected output layer with 30 values (2 for each facial keypoint)
model.add(Convolution2D(filters=32, kernel_size=5, padding='same', activation='relu', 
                        input_shape=(96, 96, 1)))

#halve the input in both spatial dimensions
model.add(MaxPooling2D(pool_size=2))
model.add(Convolution2D(filters=64, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.3))
model.add(Convolution2D(filters=128, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.3))
model.add(Convolution2D(filters=256, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))

model.add(GlobalAveragePooling2D())
model.add(Dense(500, activation='relu'))
model.add(Dropout(0.4))

#identity activation
model.add(Dense(30))

# Summarize the model
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 96, 96, 32)        832       
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 48, 48, 32)        0         
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 48, 48, 64)        8256      
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 24, 24, 64)        0         
_________________________________________________________________
dropout_1 (Dropout)          (None, 24, 24, 64)        0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 24, 24, 128)       32896     
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 12, 12, 128)       0         
_________________________________________________________________
dropout_2 (Dropout)          (None, 12, 12, 128)       0         
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 12, 12, 256)       131328    
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 6, 6, 256)         0         
_________________________________________________________________
global_average_pooling2d_1 ( (None, 256)               0         
_________________________________________________________________
dense_1 (Dense)              (None, 500)               128500    
_________________________________________________________________
dropout_3 (Dropout)          (None, 500)               0         
_________________________________________________________________
dense_2 (Dense)              (None, 30)                15030     
=================================================================
Total params: 316,842
Trainable params: 316,842
Non-trainable params: 0
_________________________________________________________________

Step 6: Compile and Train the Model

After specifying your architecture, you'll need to compile and train the model to detect facial keypoints'

(IMPLEMENTATION) Compile and Train the Model

Use the compile method to configure the learning process. Experiment with your choice of optimizer; you may have some ideas about which will work best (SGD vs. RMSprop, etc), but take the time to empirically verify your theories.

Use the fit method to train the model. Break off a validation set by setting validation_split=0.2. Save the returned History object in the history variable.

Experiment with your model to minimize the validation loss (measured as mean squared error). A very good model will achieve about 0.0015 loss (though it's possible to do even better). When you have finished training, save your model as an HDF5 file with file path my_model.h5.

In [10]:
#data augmentation by flipping images which have all 30 labels.
#since the dataset size is relatively small, resorting to pre-generate the augemented data 
#instead of going by a generator approach.

import math
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline


def flip_images(features, labels):
    print(features.shape)
    print(labels.shape)
    flip_indices = [
        (0, 2), (1, 3),
        (4, 8), (5, 9), (6, 10), (7, 11),
        (12, 16), (13, 17), (14, 18), (15, 19),
        (22, 24), (23, 25),
        ]
    flipped_features = np.zeros((len(features) * 2, 96, 96, 1))
    flipped_labels = np.zeros((len(features) * 2,30))
    
    flipped_features[:features.shape[0]] = features[:features.shape[0]]
    flipped_features[features.shape[0]:] = features[:features.shape[0]] 
    #flip the images
    flipped_features[features.shape[0]:] = flipped_features[features.shape[0]:, :, ::-1, :] 
    
    flipped_labels[:features.shape[0]] = labels[:features.shape[0]]
    flipped_labels[features.shape[0]:] = labels[:features.shape[0]]
    # Horizontal flip of all x coordinates:
    flipped_labels[features.shape[0]:, ::2] = flipped_labels[features.shape[0]:, ::2] * -1
    # Swap places, e.g. left_eye_center_x -> right_eye_center_x
    for a, b in flip_indices:
        tmp = np.copy(flipped_labels[features.shape[0]:, a])
        flipped_labels[features.shape[0]:, a] = flipped_labels[features.shape[0]:, b]
        flipped_labels[features.shape[0]:, b] = tmp   
        #the pythonic way does not seem to work somehow
        #flipped_labels[features.shape[0]:, a], flipped_labels[features.shape[0]:, b] = (
        #flipped_labels[features.shape[0]:, b], flipped_labels[features.shape[0]:, a])
            
    print(flipped_features.shape)
    print(flipped_labels.shape)
    return flipped_features, flipped_labels

#augment the data
FX_train, fy_train = flip_images(X_train, y_train) 

#test the augmented data
fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(3):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(FX_train[i], fy_train[i], ax)
  
fig1 = plt.figure(figsize=(20,20))
fig1.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(3):
    ax = fig1.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(FX_train[2140+i], fy_train[2140+i], ax) 
(2140, 96, 96, 1)
(2140, 30)
(4280, 96, 96, 1)
(4280, 30)
In [41]:
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam
from keras.callbacks import ModelCheckpoint 
import h5py

## TODO: Compile the model
model.compile(optimizer='rmsprop', loss='mean_squared_error', metrics=['accuracy'])

## TODO: Train the model
epochs = 200
checkpointer = ModelCheckpoint(filepath='saved_models/weights.best.from_scratch.hdf5', 
                               verbose=1, save_best_only=True)
#X_train data has been shuffled.
history = model.fit(FX_train, fy_train, 
          validation_split=0.20,
          epochs=epochs, batch_size=20, callbacks=[checkpointer], verbose=1)

## TODO: Save the model as model.h5
model.save('my_model.h5')
Train on 3424 samples, validate on 856 samples
Epoch 1/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0194 - acc: 0.5215Epoch 00000: val_loss improved from inf to 0.00946, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 6s - loss: 0.0193 - acc: 0.5219 - val_loss: 0.0095 - val_acc: 0.6600
Epoch 2/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0062 - acc: 0.6547Epoch 00001: val_loss improved from 0.00946 to 0.00541, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0063 - acc: 0.6539 - val_loss: 0.0054 - val_acc: 0.6600
Epoch 3/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0054 - acc: 0.6766Epoch 00002: val_loss improved from 0.00541 to 0.00528, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0054 - acc: 0.6773 - val_loss: 0.0053 - val_acc: 0.6600
Epoch 4/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0051 - acc: 0.6891Epoch 00003: val_loss improved from 0.00528 to 0.00435, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0051 - acc: 0.6893 - val_loss: 0.0043 - val_acc: 0.6600
Epoch 5/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0049 - acc: 0.6891Epoch 00004: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0049 - acc: 0.6875 - val_loss: 0.0044 - val_acc: 0.6600
Epoch 6/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0047 - acc: 0.6876Epoch 00005: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0047 - acc: 0.6866 - val_loss: 0.0045 - val_acc: 0.6600
Epoch 7/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0047 - acc: 0.6891Epoch 00006: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0047 - acc: 0.6881 - val_loss: 0.0061 - val_acc: 0.6600
Epoch 8/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0046 - acc: 0.6885Epoch 00007: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0046 - acc: 0.6878 - val_loss: 0.0044 - val_acc: 0.6600
Epoch 9/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0046 - acc: 0.6888Epoch 00008: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0046 - acc: 0.6884 - val_loss: 0.0045 - val_acc: 0.6600
Epoch 10/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0044 - acc: 0.6882Epoch 00009: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0045 - acc: 0.6884 - val_loss: 0.0045 - val_acc: 0.6612
Epoch 11/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0044 - acc: 0.6880Epoch 00010: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0044 - acc: 0.6884 - val_loss: 0.0044 - val_acc: 0.6600
Epoch 12/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0043 - acc: 0.6876Epoch 00011: val_loss improved from 0.00435 to 0.00427, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0043 - acc: 0.6875 - val_loss: 0.0043 - val_acc: 0.6600
Epoch 13/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0042 - acc: 0.6846Epoch 00012: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0042 - acc: 0.6857 - val_loss: 0.0048 - val_acc: 0.6600
Epoch 14/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0041 - acc: 0.6893Epoch 00013: val_loss improved from 0.00427 to 0.00422, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0041 - acc: 0.6881 - val_loss: 0.0042 - val_acc: 0.6600
Epoch 15/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0040 - acc: 0.6865Epoch 00014: val_loss improved from 0.00422 to 0.00390, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0040 - acc: 0.6866 - val_loss: 0.0039 - val_acc: 0.6600
Epoch 16/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0039 - acc: 0.6868Epoch 00015: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0039 - acc: 0.6869 - val_loss: 0.0041 - val_acc: 0.6600
Epoch 17/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0039 - acc: 0.6849Epoch 00016: val_loss improved from 0.00390 to 0.00355, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0038 - acc: 0.6869 - val_loss: 0.0036 - val_acc: 0.6600
Epoch 18/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0037 - acc: 0.6944Epoch 00017: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0037 - acc: 0.6942 - val_loss: 0.0043 - val_acc: 0.6706
Epoch 19/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0036 - acc: 0.6908Epoch 00018: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0036 - acc: 0.6904 - val_loss: 0.0036 - val_acc: 0.6612
Epoch 20/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0036 - acc: 0.6904Epoch 00019: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0036 - acc: 0.6907 - val_loss: 0.0037 - val_acc: 0.6624
Epoch 21/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0034 - acc: 0.6979Epoch 00020: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0034 - acc: 0.6977 - val_loss: 0.0037 - val_acc: 0.6647
Epoch 22/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0033 - acc: 0.6967Epoch 00021: val_loss improved from 0.00355 to 0.00340, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0033 - acc: 0.6963 - val_loss: 0.0034 - val_acc: 0.6741
Epoch 23/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0032 - acc: 0.7018Epoch 00022: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0032 - acc: 0.7030 - val_loss: 0.0039 - val_acc: 0.6834
Epoch 24/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0031 - acc: 0.7000Epoch 00023: val_loss improved from 0.00340 to 0.00301, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0031 - acc: 0.7004 - val_loss: 0.0030 - val_acc: 0.6612
Epoch 25/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0030 - acc: 0.6988Epoch 00024: val_loss improved from 0.00301 to 0.00282, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0030 - acc: 0.6992 - val_loss: 0.0028 - val_acc: 0.7138
Epoch 26/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0029 - acc: 0.7020Epoch 00025: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0029 - acc: 0.7024 - val_loss: 0.0033 - val_acc: 0.6764
Epoch 27/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0028 - acc: 0.7095Epoch 00026: val_loss improved from 0.00282 to 0.00256, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0028 - acc: 0.7109 - val_loss: 0.0026 - val_acc: 0.7208
Epoch 28/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0027 - acc: 0.7251Epoch 00027: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0027 - acc: 0.7249 - val_loss: 0.0027 - val_acc: 0.6857
Epoch 29/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0026 - acc: 0.7296Epoch 00028: val_loss improved from 0.00256 to 0.00231, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0026 - acc: 0.7301 - val_loss: 0.0023 - val_acc: 0.6939
Epoch 30/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0025 - acc: 0.7325Epoch 00029: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0025 - acc: 0.7331 - val_loss: 0.0032 - val_acc: 0.7150
Epoch 31/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7272Epoch 00030: val_loss improved from 0.00231 to 0.00219, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0024 - acc: 0.7275 - val_loss: 0.0022 - val_acc: 0.6951
Epoch 32/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0024 - acc: 0.7254Epoch 00031: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0024 - acc: 0.7272 - val_loss: 0.0025 - val_acc: 0.6998
Epoch 33/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0023 - acc: 0.7361Epoch 00032: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0023 - acc: 0.7357 - val_loss: 0.0029 - val_acc: 0.7523
Epoch 34/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7325Epoch 00033: val_loss improved from 0.00219 to 0.00203, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0022 - acc: 0.7334 - val_loss: 0.0020 - val_acc: 0.7652
Epoch 35/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0022 - acc: 0.7382Epoch 00034: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0022 - acc: 0.7374 - val_loss: 0.0034 - val_acc: 0.6998
Epoch 36/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7364Epoch 00035: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0021 - acc: 0.7374 - val_loss: 0.0022 - val_acc: 0.7558
Epoch 37/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0021 - acc: 0.7485Epoch 00036: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0021 - acc: 0.7488 - val_loss: 0.0021 - val_acc: 0.7699
Epoch 38/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7538Epoch 00037: val_loss improved from 0.00203 to 0.00184, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0020 - acc: 0.7529 - val_loss: 0.0018 - val_acc: 0.7734
Epoch 39/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0020 - acc: 0.7500Epoch 00038: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0020 - acc: 0.7506 - val_loss: 0.0023 - val_acc: 0.7068
Epoch 40/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7518Epoch 00039: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0019 - acc: 0.7523 - val_loss: 0.0019 - val_acc: 0.7278
Epoch 41/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7473Epoch 00040: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0019 - acc: 0.7471 - val_loss: 0.0025 - val_acc: 0.7430
Epoch 42/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0019 - acc: 0.7438Epoch 00041: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0019 - acc: 0.7442 - val_loss: 0.0021 - val_acc: 0.7371
Epoch 43/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7586Epoch 00042: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0019 - acc: 0.7567 - val_loss: 0.0019 - val_acc: 0.7371
Epoch 44/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7601Epoch 00043: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0018 - acc: 0.7602 - val_loss: 0.0025 - val_acc: 0.7535
Epoch 45/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7692Epoch 00044: val_loss improved from 0.00184 to 0.00164, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0018 - acc: 0.7690 - val_loss: 0.0016 - val_acc: 0.7652
Epoch 46/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7648Epoch 00045: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0018 - acc: 0.7649 - val_loss: 0.0025 - val_acc: 0.7570
Epoch 47/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0018 - acc: 0.7568Epoch 00046: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0018 - acc: 0.7561 - val_loss: 0.0019 - val_acc: 0.7827
Epoch 48/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7618Epoch 00047: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0017 - acc: 0.7629 - val_loss: 0.0017 - val_acc: 0.7734
Epoch 49/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7639Epoch 00048: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0017 - acc: 0.7623 - val_loss: 0.0018 - val_acc: 0.7897
Epoch 50/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7550Epoch 00049: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0017 - acc: 0.7553 - val_loss: 0.0022 - val_acc: 0.7126
Epoch 51/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0017 - acc: 0.7740Epoch 00050: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0017 - acc: 0.7737 - val_loss: 0.0021 - val_acc: 0.7021
Epoch 52/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7604Epoch 00051: val_loss improved from 0.00164 to 0.00164, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0016 - acc: 0.7608 - val_loss: 0.0016 - val_acc: 0.7874
Epoch 53/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7592Epoch 00052: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0016 - acc: 0.7585 - val_loss: 0.0018 - val_acc: 0.7827
Epoch 54/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7716Epoch 00053: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0016 - acc: 0.7710 - val_loss: 0.0022 - val_acc: 0.7769
Epoch 55/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7711Epoch 00054: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0016 - acc: 0.7704 - val_loss: 0.0017 - val_acc: 0.7921
Epoch 56/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0016 - acc: 0.7654Epoch 00055: val_loss improved from 0.00164 to 0.00159, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0016 - acc: 0.7655 - val_loss: 0.0016 - val_acc: 0.8037
Epoch 57/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7684Epoch 00056: val_loss improved from 0.00159 to 0.00154, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7681 - val_loss: 0.0015 - val_acc: 0.7699
Epoch 58/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7639Epoch 00057: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7652 - val_loss: 0.0017 - val_acc: 0.7687
Epoch 59/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7707Epoch 00058: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7693 - val_loss: 0.0019 - val_acc: 0.7301
Epoch 60/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7734Epoch 00059: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7737 - val_loss: 0.0018 - val_acc: 0.7909
Epoch 61/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7679Epoch 00060: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7690 - val_loss: 0.0016 - val_acc: 0.7722
Epoch 62/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7836Epoch 00061: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7839 - val_loss: 0.0017 - val_acc: 0.7336
Epoch 63/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7639Epoch 00062: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7646 - val_loss: 0.0017 - val_acc: 0.7652
Epoch 64/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7756Epoch 00063: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7760 - val_loss: 0.0017 - val_acc: 0.7593
Epoch 65/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0015 - acc: 0.7784Epoch 00064: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0015 - acc: 0.7783 - val_loss: 0.0017 - val_acc: 0.7815
Epoch 66/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7858Epoch 00065: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7862 - val_loss: 0.0018 - val_acc: 0.7780
Epoch 67/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7828Epoch 00066: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7827 - val_loss: 0.0016 - val_acc: 0.8002
Epoch 68/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7751Epoch 00067: val_loss improved from 0.00154 to 0.00144, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7754 - val_loss: 0.0014 - val_acc: 0.7582
Epoch 69/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7663Epoch 00068: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7669 - val_loss: 0.0018 - val_acc: 0.7371
Epoch 70/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7757Epoch 00069: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7754 - val_loss: 0.0015 - val_acc: 0.7687
Epoch 71/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7737Epoch 00070: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7737 - val_loss: 0.0018 - val_acc: 0.7301
Epoch 72/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7726Epoch 00071: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7722 - val_loss: 0.0018 - val_acc: 0.7839
Epoch 73/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7778Epoch 00072: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7777 - val_loss: 0.0015 - val_acc: 0.7734
Epoch 74/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0014 - acc: 0.7820Epoch 00073: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0014 - acc: 0.7818 - val_loss: 0.0015 - val_acc: 0.7629
Epoch 75/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7826Epoch 00074: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7813 - val_loss: 0.0018 - val_acc: 0.7477
Epoch 76/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7763Epoch 00075: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7760 - val_loss: 0.0015 - val_acc: 0.7804
Epoch 77/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7800Epoch 00076: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7795 - val_loss: 0.0014 - val_acc: 0.8026
Epoch 78/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7879Epoch 00077: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7886 - val_loss: 0.0017 - val_acc: 0.7512
Epoch 79/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7790Epoch 00078: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7789 - val_loss: 0.0014 - val_acc: 0.8061
Epoch 80/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7790Epoch 00079: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7792 - val_loss: 0.0015 - val_acc: 0.7921
Epoch 81/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7849Epoch 00080: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7848 - val_loss: 0.0016 - val_acc: 0.7862
Epoch 82/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7760Epoch 00081: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7769 - val_loss: 0.0016 - val_acc: 0.7278
Epoch 83/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7905Epoch 00082: val_loss improved from 0.00144 to 0.00140, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7909 - val_loss: 0.0014 - val_acc: 0.8096
Epoch 84/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7811Epoch 00083: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7815 - val_loss: 0.0015 - val_acc: 0.8143
Epoch 85/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7947Epoch 00084: val_loss improved from 0.00140 to 0.00140, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7953 - val_loss: 0.0014 - val_acc: 0.8213
Epoch 86/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7845Epoch 00085: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7848 - val_loss: 0.0015 - val_acc: 0.8201
Epoch 87/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7882Epoch 00086: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7888 - val_loss: 0.0014 - val_acc: 0.8026
Epoch 88/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7926Epoch 00087: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7921 - val_loss: 0.0018 - val_acc: 0.7944
Epoch 89/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0013 - acc: 0.7784Epoch 00088: val_loss improved from 0.00140 to 0.00136, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0013 - acc: 0.7792 - val_loss: 0.0014 - val_acc: 0.8119
Epoch 90/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7909Epoch 00089: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7912 - val_loss: 0.0015 - val_acc: 0.7991
Epoch 91/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7914Epoch 00090: val_loss improved from 0.00136 to 0.00136, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7918 - val_loss: 0.0014 - val_acc: 0.8026
Epoch 92/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7938Epoch 00091: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7932 - val_loss: 0.0017 - val_acc: 0.7582
Epoch 93/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7867Epoch 00092: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7877 - val_loss: 0.0015 - val_acc: 0.8119
Epoch 94/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7893Epoch 00093: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7891 - val_loss: 0.0015 - val_acc: 0.7465
Epoch 95/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7772Epoch 00094: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7769 - val_loss: 0.0016 - val_acc: 0.7944
Epoch 96/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7867Epoch 00095: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7868 - val_loss: 0.0020 - val_acc: 0.7944
Epoch 97/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7851Epoch 00096: val_loss improved from 0.00136 to 0.00130, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7850 - val_loss: 0.0013 - val_acc: 0.7956
Epoch 98/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7914Epoch 00097: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7915 - val_loss: 0.0014 - val_acc: 0.8014
Epoch 99/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7976Epoch 00098: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7973 - val_loss: 0.0016 - val_acc: 0.7991
Epoch 100/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7929Epoch 00099: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7926 - val_loss: 0.0015 - val_acc: 0.7629
Epoch 101/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7888Epoch 00100: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7880 - val_loss: 0.0017 - val_acc: 0.7956
Epoch 102/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.8038Epoch 00101: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.8037 - val_loss: 0.0013 - val_acc: 0.7979
Epoch 103/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7924Epoch 00102: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7918 - val_loss: 0.0014 - val_acc: 0.8002
Epoch 104/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7938Epoch 00103: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7938 - val_loss: 0.0014 - val_acc: 0.7979
Epoch 105/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7846Epoch 00104: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7850 - val_loss: 0.0014 - val_acc: 0.8014
Epoch 106/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7923Epoch 00105: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7918 - val_loss: 0.0016 - val_acc: 0.7815
Epoch 107/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7982Epoch 00106: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7982 - val_loss: 0.0014 - val_acc: 0.8026
Epoch 108/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7899Epoch 00107: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7894 - val_loss: 0.0014 - val_acc: 0.7769
Epoch 109/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7926Epoch 00108: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7912 - val_loss: 0.0013 - val_acc: 0.8049
Epoch 110/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7896Epoch 00109: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7912 - val_loss: 0.0014 - val_acc: 0.8189
Epoch 111/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0012 - acc: 0.7905Epoch 00110: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0012 - acc: 0.7891 - val_loss: 0.0015 - val_acc: 0.7652
Epoch 112/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7877Epoch 00111: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7877 - val_loss: 0.0014 - val_acc: 0.7383
Epoch 113/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7985Epoch 00112: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7976 - val_loss: 0.0013 - val_acc: 0.8224
Epoch 114/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7885Epoch 00113: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7888 - val_loss: 0.0017 - val_acc: 0.8026
Epoch 115/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7935Epoch 00114: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7932 - val_loss: 0.0013 - val_acc: 0.7780
Epoch 116/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7935Epoch 00115: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7923 - val_loss: 0.0013 - val_acc: 0.7979
Epoch 117/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7991Epoch 00116: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7991 - val_loss: 0.0014 - val_acc: 0.8119
Epoch 118/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7947Epoch 00117: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7953 - val_loss: 0.0016 - val_acc: 0.8131
Epoch 119/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7947Epoch 00118: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7959 - val_loss: 0.0014 - val_acc: 0.7956
Epoch 120/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8000Epoch 00119: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.8002 - val_loss: 0.0015 - val_acc: 0.8072
Epoch 121/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7882Epoch 00120: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7897 - val_loss: 0.0014 - val_acc: 0.8061
Epoch 122/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7997Epoch 00121: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7996 - val_loss: 0.0015 - val_acc: 0.8061
Epoch 123/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7956Epoch 00122: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7947 - val_loss: 0.0013 - val_acc: 0.8294
Epoch 124/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7926Epoch 00123: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7932 - val_loss: 0.0014 - val_acc: 0.8178
Epoch 125/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7787Epoch 00124: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7775 - val_loss: 0.0016 - val_acc: 0.8178
Epoch 126/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7970Epoch 00125: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7979 - val_loss: 0.0014 - val_acc: 0.8014
Epoch 127/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7828Epoch 00126: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7827 - val_loss: 0.0014 - val_acc: 0.8084
Epoch 128/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7967Epoch 00127: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7964 - val_loss: 0.0015 - val_acc: 0.8119
Epoch 129/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8018Epoch 00128: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.8023 - val_loss: 0.0013 - val_acc: 0.8037
Epoch 130/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7974Epoch 00129: val_loss improved from 0.00130 to 0.00123, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7970 - val_loss: 0.0012 - val_acc: 0.8131
Epoch 131/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7988Epoch 00130: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7988 - val_loss: 0.0014 - val_acc: 0.7640
Epoch 132/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7915Epoch 00131: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7912 - val_loss: 0.0013 - val_acc: 0.8166
Epoch 133/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7985Epoch 00132: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7988 - val_loss: 0.0014 - val_acc: 0.8294
Epoch 134/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8080Epoch 00133: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.8070 - val_loss: 0.0018 - val_acc: 0.7547
Epoch 135/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8003Epoch 00134: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.8002 - val_loss: 0.0013 - val_acc: 0.7979
Epoch 136/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7985Epoch 00135: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7988 - val_loss: 0.0013 - val_acc: 0.8131
Epoch 137/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7979Epoch 00136: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7985 - val_loss: 0.0013 - val_acc: 0.7909
Epoch 138/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7994Epoch 00137: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7996 - val_loss: 0.0013 - val_acc: 0.7874
Epoch 139/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7979Epoch 00138: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7988 - val_loss: 0.0014 - val_acc: 0.7745
Epoch 140/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7906Epoch 00139: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7909 - val_loss: 0.0014 - val_acc: 0.7897
Epoch 141/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8009Epoch 00140: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8008 - val_loss: 0.0014 - val_acc: 0.8213
Epoch 142/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7994Epoch 00141: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.7988 - val_loss: 0.0012 - val_acc: 0.8154
Epoch 143/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8029Epoch 00142: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8026 - val_loss: 0.0013 - val_acc: 0.8458
Epoch 144/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8000Epoch 00143: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8017 - val_loss: 0.0014 - val_acc: 0.7570
Epoch 145/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.8056Epoch 00144: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0011 - acc: 0.8058 - val_loss: 0.0014 - val_acc: 0.8143
Epoch 146/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0011 - acc: 0.7967Epoch 00145: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7959 - val_loss: 0.0014 - val_acc: 0.7780
Epoch 147/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7967Epoch 00146: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7964 - val_loss: 0.0013 - val_acc: 0.8049
Epoch 148/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7967Epoch 00147: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7956 - val_loss: 0.0014 - val_acc: 0.7991
Epoch 149/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8095Epoch 00148: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8087 - val_loss: 0.0013 - val_acc: 0.7792
Epoch 150/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7997Epoch 00149: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7996 - val_loss: 0.0014 - val_acc: 0.7664
Epoch 151/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8041Epoch 00150: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8040 - val_loss: 0.0013 - val_acc: 0.8201
Epoch 152/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8071Epoch 00151: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8072 - val_loss: 0.0012 - val_acc: 0.8166
Epoch 153/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8000Epoch 00152: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7999 - val_loss: 0.0013 - val_acc: 0.8107
Epoch 154/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7979Epoch 00153: val_loss improved from 0.00123 to 0.00122, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7979 - val_loss: 0.0012 - val_acc: 0.8061
Epoch 155/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8018Epoch 00154: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8005 - val_loss: 0.0013 - val_acc: 0.8236
Epoch 156/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7944Epoch 00155: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7944 - val_loss: 0.0015 - val_acc: 0.8026
Epoch 157/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8024Epoch 00156: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8017 - val_loss: 0.0013 - val_acc: 0.8318
Epoch 158/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7988Epoch 00157: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7988 - val_loss: 0.0016 - val_acc: 0.7979
Epoch 159/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8144Epoch 00158: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8145 - val_loss: 0.0013 - val_acc: 0.8271
Epoch 160/200
3400/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8053Epoch 00159: val_loss improved from 0.00122 to 0.00117, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8052 - val_loss: 0.0012 - val_acc: 0.8131
Epoch 161/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8041Epoch 00160: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8046 - val_loss: 0.0012 - val_acc: 0.7874
Epoch 162/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7944    Epoch 00161: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7941 - val_loss: 0.0013 - val_acc: 0.8178
Epoch 163/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8038Epoch 00162: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8040 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 164/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.7926Epoch 00163: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7923 - val_loss: 0.0013 - val_acc: 0.8037
Epoch 165/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8095Epoch 00164: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8099 - val_loss: 0.0013 - val_acc: 0.7827
Epoch 166/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8083Epoch 00165: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8078 - val_loss: 0.0014 - val_acc: 0.8189
Epoch 167/200
3380/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8024Epoch 00166: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8020 - val_loss: 0.0012 - val_acc: 0.8178
Epoch 168/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8000Epoch 00167: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.7996 - val_loss: 0.0014 - val_acc: 0.8119
Epoch 169/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.8301e-04 - acc: 0.8030Epoch 00168: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8305e-04 - acc: 0.8040 - val_loss: 0.0014 - val_acc: 0.7500
Epoch 170/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.8574e-04 - acc: 0.8036Epoch 00169: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8549e-04 - acc: 0.8049 - val_loss: 0.0014 - val_acc: 0.8166
Epoch 171/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.9760e-04 - acc: 0.8098Epoch 00170: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.9676e-04 - acc: 0.8102 - val_loss: 0.0014 - val_acc: 0.7991
Epoch 172/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.8713e-04 - acc: 0.8080Epoch 00171: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8529e-04 - acc: 0.8081 - val_loss: 0.0012 - val_acc: 0.8166
Epoch 173/200
3420/3424 [============================>.] - ETA: 0s - loss: 0.0010 - acc: 0.8091 Epoch 00172: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 0.0010 - acc: 0.8087 - val_loss: 0.0012 - val_acc: 0.8166
Epoch 174/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.8699e-04 - acc: 0.8041Epoch 00173: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.9032e-04 - acc: 0.8046 - val_loss: 0.0014 - val_acc: 0.7850
Epoch 175/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.8029e-04 - acc: 0.8187Epoch 00174: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8011e-04 - acc: 0.8189 - val_loss: 0.0013 - val_acc: 0.8236
Epoch 176/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.8822e-04 - acc: 0.8059Epoch 00175: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8598e-04 - acc: 0.8046 - val_loss: 0.0012 - val_acc: 0.8143
Epoch 177/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.9086e-04 - acc: 0.8033Epoch 00176: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.9331e-04 - acc: 0.8043 - val_loss: 0.0013 - val_acc: 0.8002
Epoch 178/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.7386e-04 - acc: 0.8088Epoch 00177: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.7404e-04 - acc: 0.8084 - val_loss: 0.0013 - val_acc: 0.8400
Epoch 179/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.7925e-04 - acc: 0.8059Epoch 00178: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8123e-04 - acc: 0.8064 - val_loss: 0.0013 - val_acc: 0.7722
Epoch 180/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.7677e-04 - acc: 0.8080Epoch 00179: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.7561e-04 - acc: 0.8090 - val_loss: 0.0013 - val_acc: 0.7967
Epoch 181/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.7950e-04 - acc: 0.8024Epoch 00180: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.7959e-04 - acc: 0.8017 - val_loss: 0.0013 - val_acc: 0.8248
Epoch 182/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.9662e-04 - acc: 0.8041Epoch 00181: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.9630e-04 - acc: 0.8043 - val_loss: 0.0013 - val_acc: 0.8411
Epoch 183/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.7932e-04 - acc: 0.8094Epoch 00182: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.7895e-04 - acc: 0.8093 - val_loss: 0.0012 - val_acc: 0.8143
Epoch 184/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.6160e-04 - acc: 0.7979Epoch 00183: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6073e-04 - acc: 0.7976 - val_loss: 0.0012 - val_acc: 0.8143
Epoch 185/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.7427e-04 - acc: 0.8074Epoch 00184: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.7411e-04 - acc: 0.8067 - val_loss: 0.0014 - val_acc: 0.8166
Epoch 186/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.6779e-04 - acc: 0.8076Epoch 00185: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6793e-04 - acc: 0.8072 - val_loss: 0.0013 - val_acc: 0.8037
Epoch 187/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.8477e-04 - acc: 0.7997Epoch 00186: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.8363e-04 - acc: 0.7999 - val_loss: 0.0012 - val_acc: 0.8072
Epoch 188/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.6772e-04 - acc: 0.8148Epoch 00187: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6669e-04 - acc: 0.8154 - val_loss: 0.0012 - val_acc: 0.8294
Epoch 189/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.7461e-04 - acc: 0.8130Epoch 00188: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.7340e-04 - acc: 0.8122 - val_loss: 0.0013 - val_acc: 0.8259
Epoch 190/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.6386e-04 - acc: 0.8064Epoch 00189: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6422e-04 - acc: 0.8061 - val_loss: 0.0014 - val_acc: 0.7734
Epoch 191/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.6644e-04 - acc: 0.8050Epoch 00190: val_loss improved from 0.00117 to 0.00113, saving model to saved_models/weights.best.from_scratch.hdf5
3424/3424 [==============================] - 4s - loss: 9.6628e-04 - acc: 0.8052 - val_loss: 0.0011 - val_acc: 0.8131
Epoch 192/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.6004e-04 - acc: 0.8006Epoch 00191: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.5890e-04 - acc: 0.7999 - val_loss: 0.0012 - val_acc: 0.8236
Epoch 193/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.6475e-04 - acc: 0.8062Epoch 00192: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6340e-04 - acc: 0.8061 - val_loss: 0.0013 - val_acc: 0.8178
Epoch 194/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.5624e-04 - acc: 0.8152Epoch 00193: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.5637e-04 - acc: 0.8151 - val_loss: 0.0014 - val_acc: 0.8294
Epoch 195/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.6079e-04 - acc: 0.8102Epoch 00194: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6131e-04 - acc: 0.8099 - val_loss: 0.0013 - val_acc: 0.8002
Epoch 196/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.5439e-04 - acc: 0.8061Epoch 00195: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.5437e-04 - acc: 0.8058 - val_loss: 0.0012 - val_acc: 0.8306
Epoch 197/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.6263e-04 - acc: 0.8094Epoch 00196: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6260e-04 - acc: 0.8099 - val_loss: 0.0013 - val_acc: 0.8154
Epoch 198/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.5962e-04 - acc: 0.8151Epoch 00197: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.5856e-04 - acc: 0.8157 - val_loss: 0.0013 - val_acc: 0.8154
Epoch 199/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.6981e-04 - acc: 0.8130Epoch 00198: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6849e-04 - acc: 0.8137 - val_loss: 0.0012 - val_acc: 0.8294
Epoch 200/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.6359e-04 - acc: 0.8080Epoch 00199: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.6007e-04 - acc: 0.8084 - val_loss: 0.0013 - val_acc: 0.7862
In [11]:
#since the loss visualization does not seem to indicate overfitting yet
# try training for another 200 epochs
# to see if it ends up improving or OverFitting

from keras.models import load_model
from keras.callbacks import ModelCheckpoint 

model = load_model('my_model.h5')

epochs = 200
checkpointer = ModelCheckpoint(filepath='saved_models/weights.best.ext.hdf5', 
                               verbose=1, save_best_only=True)
#X_train data has been shuffled.
history_ext = model.fit(FX_train, fy_train, 
          validation_split=0.20,
          epochs=epochs, batch_size=20, callbacks=[checkpointer], verbose=1)

## TODO: Save the model as model.h5
model.save('my_model_ext.h5')
Train on 3424 samples, validate on 856 samples
Epoch 1/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.4860e-04 - acc: 0.8126Epoch 00000: val_loss improved from inf to 0.00129, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 5s - loss: 9.4912e-04 - acc: 0.8128 - val_loss: 0.0013 - val_acc: 0.8107
Epoch 2/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.7299e-04 - acc: 0.8068Epoch 00001: val_loss improved from 0.00129 to 0.00124, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 9.7142e-04 - acc: 0.8072 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 3/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.5716e-04 - acc: 0.8059Epoch 00002: val_loss improved from 0.00124 to 0.00117, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 9.5584e-04 - acc: 0.8055 - val_loss: 0.0012 - val_acc: 0.8341
Epoch 4/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.3099e-04 - acc: 0.8085Epoch 00003: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3096e-04 - acc: 0.8084 - val_loss: 0.0012 - val_acc: 0.7886
Epoch 5/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.3390e-04 - acc: 0.8173Epoch 00004: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3365e-04 - acc: 0.8175 - val_loss: 0.0012 - val_acc: 0.7932
Epoch 6/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.5194e-04 - acc: 0.8175Epoch 00005: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.5267e-04 - acc: 0.8178 - val_loss: 0.0013 - val_acc: 0.8224
Epoch 7/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.4227e-04 - acc: 0.8156Epoch 00006: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.4243e-04 - acc: 0.8157 - val_loss: 0.0012 - val_acc: 0.8435
Epoch 8/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.4585e-04 - acc: 0.8152Epoch 00007: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.4541e-04 - acc: 0.8151 - val_loss: 0.0012 - val_acc: 0.8154
Epoch 9/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.4353e-04 - acc: 0.8079- ETA: 3s - loss:  - ETA: 2s Epoch 00008: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.4396e-04 - acc: 0.8075 - val_loss: 0.0014 - val_acc: 0.8189
Epoch 10/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.4824e-04 - acc: 0.8146Epoch 00009: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.4807e-04 - acc: 0.8145 - val_loss: 0.0013 - val_acc: 0.8014
Epoch 11/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.4338e-04 - acc: 0.8126Epoch 00010: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.4382e-04 - acc: 0.8122 - val_loss: 0.0012 - val_acc: 0.8189
Epoch 12/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.5047e-04 - acc: 0.8184Epoch 00011: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.5006e-04 - acc: 0.8183 - val_loss: 0.0012 - val_acc: 0.8353
Epoch 13/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.3729e-04 - acc: 0.8099Epoch 00012: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3803e-04 - acc: 0.8096 - val_loss: 0.0015 - val_acc: 0.8213
Epoch 14/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.2892e-04 - acc: 0.8159Epoch 00013: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3026e-04 - acc: 0.8169 - val_loss: 0.0012 - val_acc: 0.8248
Epoch 15/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.3038e-04 - acc: 0.8153Epoch 00014: val_loss improved from 0.00117 to 0.00116, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 9.3138e-04 - acc: 0.8151 - val_loss: 0.0012 - val_acc: 0.8084
Epoch 16/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.3504e-04 - acc: 0.8079Epoch 00015: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3397e-04 - acc: 0.8075 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 17/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.2939e-04 - acc: 0.8161Epoch 00016: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2905e-04 - acc: 0.8163 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 18/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.3147e-04 - acc: 0.8161Epoch 00017: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3157e-04 - acc: 0.8157 - val_loss: 0.0012 - val_acc: 0.8271
Epoch 19/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2693e-04 - acc: 0.8086Epoch 00018: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2653e-04 - acc: 0.8078 - val_loss: 0.0013 - val_acc: 0.8061
Epoch 20/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.3434e-04 - acc: 0.8030Epoch 00019: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3359e-04 - acc: 0.8034 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 21/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.3348e-04 - acc: 0.8077Epoch 00020: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3311e-04 - acc: 0.8096 - val_loss: 0.0013 - val_acc: 0.8329
Epoch 22/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.4056e-04 - acc: 0.8158Epoch 00021: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.4056e-04 - acc: 0.8157 - val_loss: 0.0012 - val_acc: 0.8329
Epoch 23/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.4107e-04 - acc: 0.8121Epoch 00022: val_loss improved from 0.00116 to 0.00115, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 9.3796e-04 - acc: 0.8110 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 24/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.1849e-04 - acc: 0.8086Epoch 00023: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1784e-04 - acc: 0.8072 - val_loss: 0.0012 - val_acc: 0.8353
Epoch 25/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.4014e-04 - acc: 0.8059Epoch 00024: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.3715e-04 - acc: 0.8061 - val_loss: 0.0013 - val_acc: 0.8213
Epoch 26/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.2598e-04 - acc: 0.8088Epoch 00025: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2596e-04 - acc: 0.8090 - val_loss: 0.0013 - val_acc: 0.8014
Epoch 27/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2382e-04 - acc: 0.8160Epoch 00026: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2418e-04 - acc: 0.8172 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 28/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.1233e-04 - acc: 0.8068Epoch 00027: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1278e-04 - acc: 0.8078 - val_loss: 0.0012 - val_acc: 0.8294
Epoch 29/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2560e-04 - acc: 0.8136Epoch 00028: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2522e-04 - acc: 0.8134 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 30/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.1709e-04 - acc: 0.8240Epoch 00029: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1568e-04 - acc: 0.8224 - val_loss: 0.0012 - val_acc: 0.8072
Epoch 31/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2372e-04 - acc: 0.8056Epoch 00030: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2866e-04 - acc: 0.8052 - val_loss: 0.0013 - val_acc: 0.8026
Epoch 32/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2503e-04 - acc: 0.8151Epoch 00031: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2571e-04 - acc: 0.8148 - val_loss: 0.0012 - val_acc: 0.8002
Epoch 33/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2955e-04 - acc: 0.8133Epoch 00032: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2988e-04 - acc: 0.8131 - val_loss: 0.0013 - val_acc: 0.8271
Epoch 34/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.2998e-04 - acc: 0.8114Epoch 00033: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2963e-04 - acc: 0.8110 - val_loss: 0.0013 - val_acc: 0.8224
Epoch 35/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.2372e-04 - acc: 0.8156Epoch 00034: val_loss improved from 0.00115 to 0.00115, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 9.2525e-04 - acc: 0.8157 - val_loss: 0.0011 - val_acc: 0.8259
Epoch 36/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.2469e-04 - acc: 0.8216Epoch 00035: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2441e-04 - acc: 0.8213 - val_loss: 0.0012 - val_acc: 0.8283
Epoch 37/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2231e-04 - acc: 0.8139Epoch 00036: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2263e-04 - acc: 0.8140 - val_loss: 0.0012 - val_acc: 0.8294
Epoch 38/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.9943e-04 - acc: 0.8096Epoch 00037: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9908e-04 - acc: 0.8096 - val_loss: 0.0012 - val_acc: 0.7944
Epoch 39/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.0717e-04 - acc: 0.8186Epoch 00038: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0673e-04 - acc: 0.8183 - val_loss: 0.0012 - val_acc: 0.8037
Epoch 40/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.0454e-04 - acc: 0.8107Epoch 00039: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0432e-04 - acc: 0.8105 - val_loss: 0.0012 - val_acc: 0.8143
Epoch 41/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.0824e-04 - acc: 0.8211Epoch 00040: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0805e-04 - acc: 0.8213 - val_loss: 0.0013 - val_acc: 0.8143
Epoch 42/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.1041e-04 - acc: 0.8145Epoch 00041: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1094e-04 - acc: 0.8145 - val_loss: 0.0013 - val_acc: 0.7757
Epoch 43/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.1229e-04 - acc: 0.8154Epoch 00042: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1144e-04 - acc: 0.8151 - val_loss: 0.0012 - val_acc: 0.7769
Epoch 44/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.2452e-04 - acc: 0.8053Epoch 00043: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.2258e-04 - acc: 0.8055 - val_loss: 0.0012 - val_acc: 0.8411
Epoch 45/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.0980e-04 - acc: 0.8178Epoch 00044: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0988e-04 - acc: 0.8175 - val_loss: 0.0012 - val_acc: 0.8423
Epoch 46/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.0149e-04 - acc: 0.8187Epoch 00045: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0138e-04 - acc: 0.8183 - val_loss: 0.0012 - val_acc: 0.7664
Epoch 47/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.1501e-04 - acc: 0.8050Epoch 00046: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1393e-04 - acc: 0.8055 - val_loss: 0.0013 - val_acc: 0.8119
Epoch 48/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.0973e-04 - acc: 0.8068Epoch 00047: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0930e-04 - acc: 0.8081 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 49/200
3400/3424 [============================>.] - ETA: 0s - loss: 9.1543e-04 - acc: 0.8265Epoch 00048: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.1333e-04 - acc: 0.8265 - val_loss: 0.0012 - val_acc: 0.8353
Epoch 50/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9966e-04 - acc: 0.8133Epoch 00049: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0214e-04 - acc: 0.8119 - val_loss: 0.0012 - val_acc: 0.8061
Epoch 51/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9923e-04 - acc: 0.8092Epoch 00050: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9864e-04 - acc: 0.8105 - val_loss: 0.0012 - val_acc: 0.8189
Epoch 52/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.0257e-04 - acc: 0.8009Epoch 00051: val_loss improved from 0.00115 to 0.00113, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 9.0344e-04 - acc: 0.8008 - val_loss: 0.0011 - val_acc: 0.7944
Epoch 53/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9989e-04 - acc: 0.8074Epoch 00052: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9903e-04 - acc: 0.8070 - val_loss: 0.0012 - val_acc: 0.7967
Epoch 54/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.0191e-04 - acc: 0.8225Epoch 00053: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0146e-04 - acc: 0.8227 - val_loss: 0.0011 - val_acc: 0.8061
Epoch 55/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9231e-04 - acc: 0.8130Epoch 00054: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9831e-04 - acc: 0.8119 - val_loss: 0.0013 - val_acc: 0.8037
Epoch 56/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8843e-04 - acc: 0.8219Epoch 00055: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8796e-04 - acc: 0.8213 - val_loss: 0.0012 - val_acc: 0.7874
Epoch 57/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.8520e-04 - acc: 0.8202Epoch 00056: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8517e-04 - acc: 0.8201 - val_loss: 0.0012 - val_acc: 0.8236
Epoch 58/200
3380/3424 [============================>.] - ETA: 0s - loss: 9.0005e-04 - acc: 0.8246Epoch 00057: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9910e-04 - acc: 0.8245 - val_loss: 0.0012 - val_acc: 0.7874
Epoch 59/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9014e-04 - acc: 0.8071Epoch 00058: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8922e-04 - acc: 0.8084 - val_loss: 0.0012 - val_acc: 0.8364
Epoch 60/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8972e-04 - acc: 0.8160Epoch 00059: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9162e-04 - acc: 0.8154 - val_loss: 0.0012 - val_acc: 0.8107
Epoch 61/200
3420/3424 [============================>.] - ETA: 0s - loss: 9.0085e-04 - acc: 0.8088Epoch 00060: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0065e-04 - acc: 0.8084 - val_loss: 0.0013 - val_acc: 0.8248
Epoch 62/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.9048e-04 - acc: 0.8149Epoch 00061: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9036e-04 - acc: 0.8145 - val_loss: 0.0012 - val_acc: 0.8411
Epoch 63/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9854e-04 - acc: 0.8178Epoch 00062: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9997e-04 - acc: 0.8175 - val_loss: 0.0013 - val_acc: 0.7687
Epoch 64/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8799e-04 - acc: 0.8192Epoch 00063: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8846e-04 - acc: 0.8198 - val_loss: 0.0013 - val_acc: 0.8201
Epoch 65/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7771e-04 - acc: 0.8059Epoch 00064: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7580e-04 - acc: 0.8061 - val_loss: 0.0013 - val_acc: 0.8224
Epoch 66/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9089e-04 - acc: 0.8160Epoch 00065: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9088e-04 - acc: 0.8169 - val_loss: 0.0011 - val_acc: 0.8294
Epoch 67/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9476e-04 - acc: 0.8136Epoch 00066: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9633e-04 - acc: 0.8131 - val_loss: 0.0014 - val_acc: 0.8248
Epoch 68/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8575e-04 - acc: 0.8148Epoch 00067: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8526e-04 - acc: 0.8154 - val_loss: 0.0012 - val_acc: 0.8131
Epoch 69/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8851e-04 - acc: 0.8095Epoch 00068: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9044e-04 - acc: 0.8078 - val_loss: 0.0012 - val_acc: 0.8049
Epoch 70/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9486e-04 - acc: 0.8180Epoch 00069: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 9.0027e-04 - acc: 0.8169 - val_loss: 0.0012 - val_acc: 0.8002
Epoch 71/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8433e-04 - acc: 0.8204Epoch 00070: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8418e-04 - acc: 0.8201 - val_loss: 0.0011 - val_acc: 0.8096
Epoch 72/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8266e-04 - acc: 0.8240Epoch 00071: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8437e-04 - acc: 0.8233 - val_loss: 0.0012 - val_acc: 0.8388
Epoch 73/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8311e-04 - acc: 0.8092Epoch 00072: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8533e-04 - acc: 0.8099 - val_loss: 0.0013 - val_acc: 0.8049
Epoch 74/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8920e-04 - acc: 0.8210Epoch 00073: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9106e-04 - acc: 0.8198 - val_loss: 0.0012 - val_acc: 0.8119
Epoch 75/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.9802e-04 - acc: 0.8152Epoch 00074: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9899e-04 - acc: 0.8151 - val_loss: 0.0013 - val_acc: 0.8096
Epoch 76/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.8670e-04 - acc: 0.8102Epoch 00075: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8767e-04 - acc: 0.8105 - val_loss: 0.0013 - val_acc: 0.8271
Epoch 77/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.8477e-04 - acc: 0.8117Epoch 00076: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8461e-04 - acc: 0.8116 - val_loss: 0.0013 - val_acc: 0.8096
Epoch 78/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.8328e-04 - acc: 0.8213Epoch 00077: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8263e-04 - acc: 0.8216 - val_loss: 0.0012 - val_acc: 0.8166
Epoch 79/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7145e-04 - acc: 0.8145Epoch 00078: val_loss improved from 0.00113 to 0.00113, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 8.7302e-04 - acc: 0.8137 - val_loss: 0.0011 - val_acc: 0.8224
Epoch 80/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8170e-04 - acc: 0.8124Epoch 00079: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8008e-04 - acc: 0.8110 - val_loss: 0.0012 - val_acc: 0.8364
Epoch 81/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8771e-04 - acc: 0.8104Epoch 00080: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8800e-04 - acc: 0.8102 - val_loss: 0.0014 - val_acc: 0.8072
Epoch 82/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.7768e-04 - acc: 0.8129Epoch 00081: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7752e-04 - acc: 0.8125 - val_loss: 0.0012 - val_acc: 0.8294
Epoch 83/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7178e-04 - acc: 0.8204Epoch 00082: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7166e-04 - acc: 0.8210 - val_loss: 0.0013 - val_acc: 0.8107
Epoch 84/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.9377e-04 - acc: 0.8124Epoch 00083: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.9524e-04 - acc: 0.8119 - val_loss: 0.0012 - val_acc: 0.7991
Epoch 85/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.8826e-04 - acc: 0.8047Epoch 00084: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8959e-04 - acc: 0.8043 - val_loss: 0.0015 - val_acc: 0.8026
Epoch 86/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8298e-04 - acc: 0.8086Epoch 00085: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8309e-04 - acc: 0.8093 - val_loss: 0.0011 - val_acc: 0.8107
Epoch 87/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8543e-04 - acc: 0.8178Epoch 00086: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8402e-04 - acc: 0.8189 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 88/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8678e-04 - acc: 0.8228Epoch 00087: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8722e-04 - acc: 0.8218 - val_loss: 0.0012 - val_acc: 0.8061
Epoch 89/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.8931e-04 - acc: 0.8144Epoch 00088: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8806e-04 - acc: 0.8131 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 90/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.6884e-04 - acc: 0.8191Epoch 00089: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6779e-04 - acc: 0.8186 - val_loss: 0.0011 - val_acc: 0.8201
Epoch 91/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8084e-04 - acc: 0.8092Epoch 00090: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8227e-04 - acc: 0.8110 - val_loss: 0.0012 - val_acc: 0.8084
Epoch 92/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7327e-04 - acc: 0.8095Epoch 00091: val_loss improved from 0.00113 to 0.00110, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 8.7080e-04 - acc: 0.8090 - val_loss: 0.0011 - val_acc: 0.8283
Epoch 93/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.7997e-04 - acc: 0.8178Epoch 00092: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8012e-04 - acc: 0.8180 - val_loss: 0.0013 - val_acc: 0.7780
Epoch 94/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.7280e-04 - acc: 0.8155Epoch 00093: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7312e-04 - acc: 0.8154 - val_loss: 0.0012 - val_acc: 0.8353
Epoch 95/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7850e-04 - acc: 0.8124Epoch 00094: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7814e-04 - acc: 0.8125 - val_loss: 0.0011 - val_acc: 0.8107
Epoch 96/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7245e-04 - acc: 0.8169Epoch 00095: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7411e-04 - acc: 0.8178 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 97/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.7112e-04 - acc: 0.8244Epoch 00096: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7151e-04 - acc: 0.8236 - val_loss: 0.0011 - val_acc: 0.8341
Epoch 98/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.7121e-04 - acc: 0.8117Epoch 00097: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7092e-04 - acc: 0.8116 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 99/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8181e-04 - acc: 0.8121Epoch 00098: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8215e-04 - acc: 0.8134 - val_loss: 0.0012 - val_acc: 0.8131
Epoch 100/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8150e-04 - acc: 0.8169Epoch 00099: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.8050e-04 - acc: 0.8166 - val_loss: 0.0015 - val_acc: 0.7745
Epoch 101/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6104e-04 - acc: 0.8115Epoch 00100: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5972e-04 - acc: 0.8119 - val_loss: 0.0013 - val_acc: 0.7932
Epoch 102/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6017e-04 - acc: 0.8139Epoch 00101: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6171e-04 - acc: 0.8128 - val_loss: 0.0013 - val_acc: 0.8061
Epoch 103/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.7215e-04 - acc: 0.8059Epoch 00102: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7065e-04 - acc: 0.8064 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 104/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.8099e-04 - acc: 0.8142Epoch 00103: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7994e-04 - acc: 0.8137 - val_loss: 0.0013 - val_acc: 0.7956
Epoch 105/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7069e-04 - acc: 0.8183Epoch 00104: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7118e-04 - acc: 0.8183 - val_loss: 0.0011 - val_acc: 0.8213
Epoch 106/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.6920e-04 - acc: 0.8096Epoch 00105: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6910e-04 - acc: 0.8099 - val_loss: 0.0012 - val_acc: 0.8271
Epoch 107/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6185e-04 - acc: 0.8210Epoch 00106: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6311e-04 - acc: 0.8201 - val_loss: 0.0012 - val_acc: 0.8049
Epoch 108/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5383e-04 - acc: 0.8234Epoch 00107: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5634e-04 - acc: 0.8218 - val_loss: 0.0012 - val_acc: 0.8248
Epoch 109/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6433e-04 - acc: 0.8157Epoch 00108: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6385e-04 - acc: 0.8148 - val_loss: 0.0013 - val_acc: 0.8037
Epoch 110/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.7044e-04 - acc: 0.8172Epoch 00109: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.7026e-04 - acc: 0.8186 - val_loss: 0.0012 - val_acc: 0.8364
Epoch 111/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6194e-04 - acc: 0.8104Epoch 00110: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6181e-04 - acc: 0.8119 - val_loss: 0.0012 - val_acc: 0.8178
Epoch 112/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5999e-04 - acc: 0.8151Epoch 00111: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5888e-04 - acc: 0.8166 - val_loss: 0.0011 - val_acc: 0.8189
Epoch 113/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5936e-04 - acc: 0.8166Epoch 00112: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5909e-04 - acc: 0.8169 - val_loss: 0.0014 - val_acc: 0.7944
Epoch 114/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.6459e-04 - acc: 0.8193Epoch 00113: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6514e-04 - acc: 0.8192 - val_loss: 0.0013 - val_acc: 0.7839
Epoch 115/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5373e-04 - acc: 0.8166Epoch 00114: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5343e-04 - acc: 0.8160 - val_loss: 0.0013 - val_acc: 0.8119
Epoch 116/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5778e-04 - acc: 0.8133Epoch 00115: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5763e-04 - acc: 0.8134 - val_loss: 0.0018 - val_acc: 0.7897
Epoch 117/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.6425e-04 - acc: 0.8114Epoch 00116: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6453e-04 - acc: 0.8113 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 118/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6724e-04 - acc: 0.8228Epoch 00117: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6493e-04 - acc: 0.8227 - val_loss: 0.0012 - val_acc: 0.8283
Epoch 119/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6346e-04 - acc: 0.8240Epoch 00118: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6565e-04 - acc: 0.8242 - val_loss: 0.0011 - val_acc: 0.8143
Epoch 120/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4881e-04 - acc: 0.8130Epoch 00119: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4962e-04 - acc: 0.8131 - val_loss: 0.0011 - val_acc: 0.8213
Epoch 121/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6267e-04 - acc: 0.8207Epoch 00120: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6162e-04 - acc: 0.8201 - val_loss: 0.0011 - val_acc: 0.8364
Epoch 122/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.6228e-04 - acc: 0.8129Epoch 00121: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6182e-04 - acc: 0.8125 - val_loss: 0.0013 - val_acc: 0.8224
Epoch 123/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.5605e-04 - acc: 0.8219Epoch 00122: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5617e-04 - acc: 0.8218 - val_loss: 0.0013 - val_acc: 0.8306
Epoch 124/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4884e-04 - acc: 0.8234Epoch 00123: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4931e-04 - acc: 0.8230 - val_loss: 0.0012 - val_acc: 0.8189
Epoch 125/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.6249e-04 - acc: 0.8123Epoch 00124: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6273e-04 - acc: 0.8119 - val_loss: 0.0012 - val_acc: 0.8061
Epoch 126/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5540e-04 - acc: 0.8178Epoch 00125: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5533e-04 - acc: 0.8157 - val_loss: 0.0012 - val_acc: 0.8294
Epoch 127/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4870e-04 - acc: 0.8129Epoch 00126: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4888e-04 - acc: 0.8131 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 128/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6661e-04 - acc: 0.8115Epoch 00127: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6577e-04 - acc: 0.8102 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 129/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.6577e-04 - acc: 0.8229Epoch 00128: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6460e-04 - acc: 0.8233 - val_loss: 0.0011 - val_acc: 0.8143
Epoch 130/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.6792e-04 - acc: 0.8109Epoch 00129: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.6612e-04 - acc: 0.8102 - val_loss: 0.0014 - val_acc: 0.7874
Epoch 131/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5599e-04 - acc: 0.8160Epoch 00130: val_loss improved from 0.00110 to 0.00110, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 8.5564e-04 - acc: 0.8157 - val_loss: 0.0011 - val_acc: 0.8411
Epoch 132/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4966e-04 - acc: 0.8207Epoch 00131: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4856e-04 - acc: 0.8195 - val_loss: 0.0011 - val_acc: 0.8224
Epoch 133/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4468e-04 - acc: 0.8222Epoch 00132: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4603e-04 - acc: 0.8224 - val_loss: 0.0012 - val_acc: 0.8026
Epoch 134/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4326e-04 - acc: 0.8219Epoch 00133: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4377e-04 - acc: 0.8218 - val_loss: 0.0012 - val_acc: 0.8271
Epoch 135/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5593e-04 - acc: 0.8257Epoch 00134: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5871e-04 - acc: 0.8262 - val_loss: 0.0012 - val_acc: 0.7956
Epoch 136/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5299e-04 - acc: 0.8201Epoch 00135: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5329e-04 - acc: 0.8198 - val_loss: 0.0012 - val_acc: 0.8248
Epoch 137/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3680e-04 - acc: 0.8186Epoch 00136: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3674e-04 - acc: 0.8186 - val_loss: 0.0012 - val_acc: 0.7944
Epoch 138/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4718e-04 - acc: 0.8164Epoch 00137: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4705e-04 - acc: 0.8163 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 139/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5554e-04 - acc: 0.8204Epoch 00138: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5664e-04 - acc: 0.8204 - val_loss: 0.0013 - val_acc: 0.8107
Epoch 140/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5190e-04 - acc: 0.8115Epoch 00139: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5062e-04 - acc: 0.8119 - val_loss: 0.0012 - val_acc: 0.8107
Epoch 141/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4851e-04 - acc: 0.8178Epoch 00140: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4728e-04 - acc: 0.8180 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 142/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5371e-04 - acc: 0.8178Epoch 00141: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5549e-04 - acc: 0.8169 - val_loss: 0.0013 - val_acc: 0.8259
Epoch 143/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4949e-04 - acc: 0.8175Epoch 00142: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4898e-04 - acc: 0.8172 - val_loss: 0.0012 - val_acc: 0.7991
Epoch 144/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5493e-04 - acc: 0.8095Epoch 00143: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5577e-04 - acc: 0.8096 - val_loss: 0.0011 - val_acc: 0.8201
Epoch 145/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.5089e-04 - acc: 0.8132Epoch 00144: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5081e-04 - acc: 0.8131 - val_loss: 0.0013 - val_acc: 0.8283
Epoch 146/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3835e-04 - acc: 0.8170Epoch 00145: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3824e-04 - acc: 0.8169 - val_loss: 0.0012 - val_acc: 0.8107
Epoch 147/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4880e-04 - acc: 0.8237Epoch 00146: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4706e-04 - acc: 0.8242 - val_loss: 0.0011 - val_acc: 0.8119
Epoch 148/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.3630e-04 - acc: 0.8253Epoch 00147: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3737e-04 - acc: 0.8248 - val_loss: 0.0012 - val_acc: 0.8435
Epoch 149/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.4482e-04 - acc: 0.8156Epoch 00148: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4785e-04 - acc: 0.8157 - val_loss: 0.0012 - val_acc: 0.7991
Epoch 150/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3333e-04 - acc: 0.8142Epoch 00149: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3295e-04 - acc: 0.8143 - val_loss: 0.0012 - val_acc: 0.8283
Epoch 151/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5139e-04 - acc: 0.8186Epoch 00150: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4930e-04 - acc: 0.8189 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 152/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4502e-04 - acc: 0.8111Epoch 00151: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4499e-04 - acc: 0.8113 - val_loss: 0.0012 - val_acc: 0.8166
Epoch 153/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4671e-04 - acc: 0.8284Epoch 00152: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4665e-04 - acc: 0.8283 - val_loss: 0.0012 - val_acc: 0.8189
Epoch 154/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4955e-04 - acc: 0.8207Epoch 00153: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4838e-04 - acc: 0.8198 - val_loss: 0.0012 - val_acc: 0.8143
Epoch 155/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.5722e-04 - acc: 0.8135Epoch 00154: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5716e-04 - acc: 0.8137 - val_loss: 0.0013 - val_acc: 0.7804
Epoch 156/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.5015e-04 - acc: 0.8275Epoch 00155: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4999e-04 - acc: 0.8277 - val_loss: 0.0012 - val_acc: 0.8224
Epoch 157/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4967e-04 - acc: 0.8225Epoch 00156: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5140e-04 - acc: 0.8227 - val_loss: 0.0012 - val_acc: 0.7944
Epoch 158/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3889e-04 - acc: 0.8195Epoch 00157: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4291e-04 - acc: 0.8186 - val_loss: 0.0014 - val_acc: 0.8014
Epoch 159/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.5377e-04 - acc: 0.8111Epoch 00158: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5392e-04 - acc: 0.8113 - val_loss: 0.0012 - val_acc: 0.7944
Epoch 160/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3242e-04 - acc: 0.8170Epoch 00159: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3254e-04 - acc: 0.8169 - val_loss: 0.0012 - val_acc: 0.8248
Epoch 161/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5300e-04 - acc: 0.8142Epoch 00160: val_loss improved from 0.00110 to 0.00110, saving model to saved_models/weights.best.ext.hdf5
3424/3424 [==============================] - 4s - loss: 8.5275e-04 - acc: 0.8154 - val_loss: 0.0011 - val_acc: 0.7991
Epoch 162/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3062e-04 - acc: 0.8137Epoch 00161: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3201e-04 - acc: 0.8140 - val_loss: 0.0013 - val_acc: 0.8283
Epoch 163/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4983e-04 - acc: 0.8145Epoch 00162: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5028e-04 - acc: 0.8145 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 164/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4815e-04 - acc: 0.8082Epoch 00163: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4815e-04 - acc: 0.8084 - val_loss: 0.0011 - val_acc: 0.8236
Epoch 165/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3745e-04 - acc: 0.8167Epoch 00164: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3705e-04 - acc: 0.8166 - val_loss: 0.0012 - val_acc: 0.8178
Epoch 166/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3164e-04 - acc: 0.8263Epoch 00165: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3364e-04 - acc: 0.8280 - val_loss: 0.0012 - val_acc: 0.8154
Epoch 167/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.2773e-04 - acc: 0.8209Epoch 00166: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2739e-04 - acc: 0.8207 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 168/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.5309e-04 - acc: 0.8180Epoch 00167: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5218e-04 - acc: 0.8192 - val_loss: 0.0012 - val_acc: 0.7827
Epoch 169/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3306e-04 - acc: 0.8172Epoch 00168: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3329e-04 - acc: 0.8169 - val_loss: 0.0012 - val_acc: 0.7769
Epoch 170/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3011e-04 - acc: 0.8199Epoch 00169: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3043e-04 - acc: 0.8195 - val_loss: 0.0013 - val_acc: 0.7687
Epoch 171/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3969e-04 - acc: 0.8095Epoch 00170: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3678e-04 - acc: 0.8107 - val_loss: 0.0013 - val_acc: 0.7979
Epoch 172/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.3270e-04 - acc: 0.8197Epoch 00171: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3140e-04 - acc: 0.8204 - val_loss: 0.0011 - val_acc: 0.7897
Epoch 173/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4203e-04 - acc: 0.8143Epoch 00172: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4288e-04 - acc: 0.8145 - val_loss: 0.0012 - val_acc: 0.8049
Epoch 174/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.2836e-04 - acc: 0.8263Epoch 00173: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2874e-04 - acc: 0.8262 - val_loss: 0.0012 - val_acc: 0.7967
Epoch 175/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3238e-04 - acc: 0.8198Epoch 00174: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3050e-04 - acc: 0.8210 - val_loss: 0.0012 - val_acc: 0.8166
Epoch 176/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3906e-04 - acc: 0.8249Epoch 00175: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3869e-04 - acc: 0.8251 - val_loss: 0.0011 - val_acc: 0.8411
Epoch 177/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3360e-04 - acc: 0.8139Epoch 00176: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3415e-04 - acc: 0.8143 - val_loss: 0.0011 - val_acc: 0.8318
Epoch 178/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.1864e-04 - acc: 0.8240Epoch 00177: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.1913e-04 - acc: 0.8242 - val_loss: 0.0012 - val_acc: 0.8283
Epoch 179/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4711e-04 - acc: 0.8172Epoch 00178: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4628e-04 - acc: 0.8178 - val_loss: 0.0011 - val_acc: 0.7979
Epoch 180/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3967e-04 - acc: 0.8189Epoch 00179: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4058e-04 - acc: 0.8192 - val_loss: 0.0012 - val_acc: 0.8201
Epoch 181/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4397e-04 - acc: 0.8317Epoch 00180: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4437e-04 - acc: 0.8327 - val_loss: 0.0013 - val_acc: 0.8143
Epoch 182/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.2672e-04 - acc: 0.8154Epoch 00181: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2562e-04 - acc: 0.8166 - val_loss: 0.0012 - val_acc: 0.8178
Epoch 183/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.1854e-04 - acc: 0.8209Epoch 00182: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.1982e-04 - acc: 0.8207 - val_loss: 0.0013 - val_acc: 0.7769
Epoch 184/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3037e-04 - acc: 0.8213Epoch 00183: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3055e-04 - acc: 0.8216 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 185/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.2656e-04 - acc: 0.8195Epoch 00184: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2778e-04 - acc: 0.8192 - val_loss: 0.0012 - val_acc: 0.8178
Epoch 186/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.2600e-04 - acc: 0.8208Epoch 00185: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2629e-04 - acc: 0.8210 - val_loss: 0.0013 - val_acc: 0.8236
Epoch 187/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.4973e-04 - acc: 0.8259Epoch 00186: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.5029e-04 - acc: 0.8265 - val_loss: 0.0011 - val_acc: 0.8131
Epoch 188/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.3117e-04 - acc: 0.8138Epoch 00187: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3207e-04 - acc: 0.8140 - val_loss: 0.0011 - val_acc: 0.7991
Epoch 189/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.3428e-04 - acc: 0.8275Epoch 00188: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3414e-04 - acc: 0.8277 - val_loss: 0.0013 - val_acc: 0.7792
Epoch 190/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.2505e-04 - acc: 0.8263Epoch 00189: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2521e-04 - acc: 0.8262 - val_loss: 0.0012 - val_acc: 0.8143
Epoch 191/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4052e-04 - acc: 0.8237Epoch 00190: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3910e-04 - acc: 0.8230 - val_loss: 0.0011 - val_acc: 0.8318
Epoch 192/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.4105e-04 - acc: 0.8124Epoch 00191: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3995e-04 - acc: 0.8125 - val_loss: 0.0012 - val_acc: 0.7862
Epoch 193/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.3295e-04 - acc: 0.8246Epoch 00192: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3347e-04 - acc: 0.8245 - val_loss: 0.0012 - val_acc: 0.8189
Epoch 194/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.4169e-04 - acc: 0.8260Epoch 00193: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.4231e-04 - acc: 0.8259 - val_loss: 0.0012 - val_acc: 0.7956
Epoch 195/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.2960e-04 - acc: 0.8163Epoch 00194: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.3236e-04 - acc: 0.8151 - val_loss: 0.0013 - val_acc: 0.8271
Epoch 196/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.2865e-04 - acc: 0.8222Epoch 00195: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2824e-04 - acc: 0.8216 - val_loss: 0.0012 - val_acc: 0.8154
Epoch 197/200
3420/3424 [============================>.] - ETA: 0s - loss: 8.2289e-04 - acc: 0.8193Epoch 00196: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2252e-04 - acc: 0.8192 - val_loss: 0.0012 - val_acc: 0.8213
Epoch 198/200
3400/3424 [============================>.] - ETA: 0s - loss: 8.2156e-04 - acc: 0.8138Epoch 00197: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2238e-04 - acc: 0.8145 - val_loss: 0.0012 - val_acc: 0.7991
Epoch 199/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.2406e-04 - acc: 0.8136Epoch 00198: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.2419e-04 - acc: 0.8143 - val_loss: 0.0012 - val_acc: 0.8388
Epoch 200/200
3380/3424 [============================>.] - ETA: 0s - loss: 8.1835e-04 - acc: 0.8189Epoch 00199: val_loss did not improve
3424/3424 [==============================] - 4s - loss: 8.1801e-04 - acc: 0.8186 - val_loss: 0.0012 - val_acc: 0.8236

Step 7: Visualize the Loss and Test Predictions

(IMPLEMENTATION) Answer a few questions and visualize the loss

Question 1: Outline the steps you took to get to your final neural network architecture and your reasoning at each step.

Answer:

  1. 4 convolutional layers with filter increasing from 32 to 256. This is based on what has been taught in the lectures on CNN's.

  2. Maxpooling layer after each convolutional layer to halve the input in both spatial dimensions

  3. Tried a GAP layer instead of a vanilla Flatten before feeding to the fully connected hidden layer's. Though the GAP layer was demonstrated in earlier lectures in a classification context, i wanted to see if the localization feature of the GAP layer would help here.

  4. One Densely connected hidden layer with 500 units. Tried to use two hidden layers but it did not improve the results in terms of Validation Loss.

  5. Final Output layer with 30 units and Identity activation for the 15 keypoints.

  6. During the traning, i found the model overfitting the data and hence added Dropout layers in between.

  7. Tried to increase the batchsize from 20 to 100 hoping it would generalize better, but the results were not very encouraging.

  8. Increasing the Kernel size for the Convolutions was again found counterproductive.

  9. Performed Data Augmentation by flipping the images returned by utils.load_data. Wanted to use a generator implementation, but then figured that since the total set of images is small, it was lot simpler to pre-create the Augmented Dataset and train the model on augmented data.

Question 2: Defend your choice of optimizer. Which optimizers did you test, and how did you determine which worked best?

Answer:

  1. Looked at http://cs.stanford.edu/people/karpathy/convnetjs/demo/trainers.html and http://danielnouri.org/notes/2014/12/17/using-convolutional-neural-nets-to-detect-facial-keypoints-tutorial/

    where they compared the various algorithms.

  2. Tried Adadelta, RMSProp and SGD with Nestrov=True. However i could not tune the SGD parameters well enough to get a good optimizer. Instead i observed that RMSProp was performing the best, so i used RMSProp.

  3. A Comparision of Validation Loss with Epochs (for 50 Epochs) for 3 optimizers is attached in this notebook as screen captures.

Use the code cell below to plot the training and validation loss of your neural network. You may find this resource useful.

In [20]:
import cv2
import matplotlib.pyplot as plt

%matplotlib inline

# Load in color image for face detection
image1 = cv2.imread('adadelta-50epochs.jpeg')
image2 = cv2.imread('rmsprop-capstone.jpeg')
image3 = cv2.imread('sgd-capstone-plot.jpeg')
image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB)
image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2RGB)
image3 = cv2.cvtColor(image3, cv2.COLOR_BGR2RGB)

# Display the image with the detections
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(331)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Adadelta 50 Epochs')
ax1.imshow(image1)


ax2 = fig.add_subplot(332)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('RMSProp 50 Epochs')
ax2.imshow(image2)

ax3 = fig.add_subplot(333)
ax3.set_xticks([])
ax3.set_yticks([])

ax3.set_title('SGD Nestrov=True 50 Epochs')
ax3.imshow(image3)
Out[20]:
<matplotlib.image.AxesImage at 0x7f2f8108e860>
In [42]:
## TODO: Visualize the training and validation loss of your neural network
import matplotlib.pyplot as plt
import numpy

%matplotlib inline

## TODO: Visualize the training and validation loss of your neural network
print(history.history.keys())
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper left')
plt.show()
dict_keys(['val_loss', 'acc', 'val_acc', 'loss'])
In [13]:
## Visualize the Extended Traning Model's Loss
import matplotlib.pyplot as plt
import numpy

%matplotlib inline

## TODO: Visualize the training and validation loss of your neural network
print(history_ext.history.keys())
# summarize history for accuracy
plt.plot(history_ext.history['acc'])
plt.plot(history_ext.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history_ext.history['loss'])
plt.plot(history_ext.history['val_loss'])
plt.title('model loss : Seems to be OverFitting')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper left')
plt.show()
dict_keys(['val_acc', 'acc', 'loss', 'val_loss'])

Question 3: Do you notice any evidence of overfitting or underfitting in the above plot? If so, what steps have you taken to improve your model? Note that slight overfitting or underfitting will not hurt your chances of a successful submission, as long as you have attempted some solutions towards improving your model (such as regularization, dropout, increased/decreased number of layers, etc).

Answer: After traning my network for 200 Epochs, it appeared the model was not really overfitting till that point. So i initialized the model again with the weights from 200 Epochs and tried to re-train for a further 200 Epochs. This time it appeared to overfit the model as shown above as the validation loss started to increase slightly with progress of epochs.

In general i used Dropout in the network to improve the model.

Visualize a Subset of the Test Predictions

Execute the code cell below to visualize your model's predicted keypoints on a subset of the testing images.

In [43]:
y_test = model.predict(X_test)
fig = plt.figure(figsize=(20,20))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(9):
    ax = fig.add_subplot(3, 3, i + 1, xticks=[], yticks=[])
    plot_data(X_test[i], y_test[i], ax)

Step 8: Complete the pipeline

With the work you did in Sections 1 and 2 of this notebook, along with your freshly trained facial keypoint detector, you can now complete the full pipeline. That is given a color image containing a person or persons you can now

  • Detect the faces in this image automatically using OpenCV
  • Predict the facial keypoints in each face detected in the image
  • Paint predicted keypoints on each face detected

In this Subsection you will do just this!

(IMPLEMENTATION) Facial Keypoints Detector

Use the OpenCV face detection functionality you built in previous Sections to expand the functionality of your keypoints detector to color images with arbitrary size. Your function should perform the following steps

  1. Accept a color image.
  2. Convert the image to grayscale.
  3. Detect and crop the face contained in the image.
  4. Locate the facial keypoints in the cropped image.
  5. Overlay the facial keypoints in the original (color, uncropped) image.

Note: step 4 can be the trickiest because remember your convolutional network is only trained to detect facial keypoints in $96 \times 96$ grayscale images where each pixel was normalized to lie in the interval $[0,1]$, and remember that each facial keypoint was normalized during training to the interval $[-1,1]$. This means - practically speaking - to paint detected keypoints onto a test face you need to perform this same pre-processing to your candidate face - that is after detecting it you should resize it to $96 \times 96$ and normalize its values before feeding it into your facial keypoint detector. To be shown correctly on the original image the output keypoints from your detector then need to be shifted and re-normalized from the interval $[-1,1]$ to the width and height of your detected face.

When complete you should be able to produce example images like the one below

In [1]:
import cv2
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline

# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_copy = np.copy(image)
# plot our image
fig = plt.figure(figsize = (9,9))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('image')
ax1.imshow(image_copy)
Out[1]:
<matplotlib.image.AxesImage at 0x7f300c72b630>
In [28]:
from keras.models import load_model
import cv2
import numpy as np


### TODO: Use the face detection code we saw in Section 1 with your trained conv-net 
## TODO : Paint the predicted keypoints on the test image
 
gray = cv2.cvtColor(image_copy, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.17, 6, 1, (100,100))
# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))


print(image_copy.shape)
# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_copy)


# Display the image with the detections
fig = plt.figure(figsize = (30,30))
ax1 = fig.add_subplot(221)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image_copy)


ax2 = fig.add_subplot(222)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Image with Face Detections and Keypoints')
ax2.imshow(image_with_detections)


# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    rectangle = cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    ax2.imshow(rectangle)
     
    bgr_crop = image_copy[y:y+h, x:x+w] 
    orig_shape_crop = bgr_crop.shape
    gray_crop = cv2.cvtColor(bgr_crop, cv2.COLOR_RGB2GRAY)
    resize_gray_crop = cv2.resize(gray_crop, (96, 96)) / 255.
    model = load_model('my_model.h5')
    landmarks = np.squeeze(model.predict(
    np.expand_dims(np.expand_dims(resize_gray_crop, axis=-1), axis=0)))
    ax2.scatter(((landmarks[0::2] * 48 + 48)*orig_shape_crop[0]/96)+x, 
    ((landmarks[1::2] * 48 + 48)*orig_shape_crop[1]/96)+y, marker='*', c='xkcd:lime green', s=10)
    
    
Number of faces detected: 2
(500, 759, 3)

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add facial keypoint detection to your laptop camera - as illustrated in the gif below.

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for keypoint detection and marking in the previous exercise and you should be good to go!

In [ ]:
import cv2
import time 
from keras.models import load_model
def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # Try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # keep video stream open
    while rval:
        # plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # destroy windows
            cv2.destroyAllWindows()
            
            # hack from stack overflow for making sure window closes on osx --> https://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()  
In [ ]:
# Run your keypoint face painter
laptop_camera_go()

(Optional) Further Directions - add a filter using facial keypoints

Using your freshly minted facial keypoint detector pipeline you can now do things like add fun filters to a person's face automatically. In this optional exercise you can play around with adding sunglasses automatically to each individual's face in an image as shown in a demonstration image below.

To produce this effect an image of a pair of sunglasses shown in the Python cell below.

In [4]:
import cv2
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline
# Load in sunglasses image - note the usage of the special option
# cv2.IMREAD_UNCHANGED, this option is used because the sunglasses 
# image has a 4th channel that allows us to control how transparent each pixel in the image is
sunglasses = cv2.imread("images/sunglasses_4.png", cv2.IMREAD_UNCHANGED)

# Plot the image
fig = plt.figure(figsize = (6,6))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.imshow(sunglasses)
ax1.axis('off');

This image is placed over each individual's face using the detected eye points to determine the location of the sunglasses, and eyebrow points to determine the size that the sunglasses should be for each person (one could also use the nose point to determine this).

Notice that this image actually has 4 channels, not just 3.

In [5]:
# Print out the shape of the sunglasses image
print ('The sunglasses image has shape: ' + str(np.shape(sunglasses)))
The sunglasses image has shape: (1123, 3064, 4)

It has the usual red, blue, and green channels any color image has, with the 4th channel representing the transparency level of each pixel in the image. Here's how the transparency channel works: the lower the value, the more transparent the pixel will become. The lower bound (completely transparent) is zero here, so any pixels set to 0 will not be seen.

This is how we can place this image of sunglasses on someone's face and still see the area around of their face where the sunglasses lie - because these pixels in the sunglasses image have been made completely transparent.

Lets check out the alpha channel of our sunglasses image in the next Python cell. Note because many of the pixels near the boundary are transparent we'll need to explicitly print out non-zero values if we want to see them.

In [6]:
# Print out the sunglasses transparency (alpha) channel
alpha_channel = sunglasses[:,:,3]
print ('the alpha channel here looks like')
print (alpha_channel)

# Just to double check that there are indeed non-zero values
# Let's find and print out every value greater than zero
values = np.where(alpha_channel != 0)
print ('\n the non-zero values of the alpha channel look like')
print (values)
the alpha channel here looks like
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

 the non-zero values of the alpha channel look like
(array([  17,   17,   17, ..., 1109, 1109, 1109]), array([ 687,  688,  689, ..., 2376, 2377, 2378]))

This means that when we place this sunglasses image on top of another image, we can use the transparency channel as a filter to tell us which pixels to overlay on a new image (only the non-transparent ones with values greater than zero).

One last thing: it's helpful to understand which keypoint belongs to the eyes, mouth, etc. So, in the image below, we also display the index of each facial keypoint directly on the image so that you can tell which keypoints are for the eyes, eyebrows, etc.

With this information, you're well on your way to completing this filtering task! See if you can place the sunglasses automatically on the individuals in the image loaded in / shown in the next Python cell.

In [7]:
# Load in color image for face detection
image = cv2.imread('images/obamas4.jpg')

# Convert the image to RGB colorspace
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)


# Plot the image
fig = plt.figure(figsize = (8,8))
ax1 = fig.add_subplot(111)
ax1.set_xticks([])
ax1.set_yticks([])
ax1.set_title('Original Image')
ax1.imshow(image)
Out[7]:
<matplotlib.image.AxesImage at 0x7f09d12a1e80>
In [8]:
## (Optional) TODO: Use the face detection code we saw in Section 1 with your trained conv-net to put
## sunglasses on the individuals in our test image
from keras.models import load_model
import cv2
import numpy as np


image_copy = np.copy(image)
### TODO: Use the face detection code we saw in Section 1 with your trained conv-net 
## TODO : Paint the predicted keypoints on the test image
 
gray = cv2.cvtColor(image_copy, cv2.COLOR_RGB2GRAY)

# Extract the pre-trained face detector from an xml file
face_cascade = cv2.CascadeClassifier('detector_architectures/haarcascade_frontalface_default.xml')

# Detect the faces in image
faces = face_cascade.detectMultiScale(gray, 1.17, 6, 1, (100,100))
# Print the number of faces detected in the image
print('Number of faces detected:', len(faces))


print(image_copy.shape)
# Make a copy of the orginal image to draw face detections on
image_with_detections = np.copy(image_copy)


# Display the image with the detections
fig = plt.figure(figsize = (20,20))
ax1 = fig.add_subplot(221)
ax1.set_xticks([])
ax1.set_yticks([])

ax1.set_title('Original Image')
ax1.imshow(image_copy)


ax2 = fig.add_subplot(222)
ax2.set_xticks([])
ax2.set_yticks([])

ax2.set_title('Image with Face Detections and Keypoints')
ax2.imshow(image_with_detections)


# Get the bounding box for each detected face
for (x,y,w,h) in faces:
    # Add a red bounding box to the detections image
    rectangle = cv2.rectangle(image_with_detections, (x,y), (x+w,y+h), (255,0,0), 3)
    ax2.imshow(rectangle)
     
    bgr_crop = image_copy[y:y+h, x:x+w] 
    orig_shape_crop = bgr_crop.shape
    gray_crop = cv2.cvtColor(bgr_crop, cv2.COLOR_RGB2GRAY)
    resize_gray_crop = cv2.resize(gray_crop, (96, 96)) / 255.
    model = load_model('my_model.h5')
    landmarks = np.squeeze(model.predict(
    np.expand_dims(np.expand_dims(resize_gray_crop, axis=-1), axis=0)))
    
    
Number of faces detected: 2
(500, 759, 3)

(Optional) Further Directions - add a filter using facial keypoints to your laptop camera

Now you can add the sunglasses filter to your laptop camera - as illustrated in the gif below.

The next Python cell contains the basic laptop video camera function used in the previous optional video exercises. Combine it with the functionality you developed for adding sunglasses to someone's face in the previous optional exercise and you should be good to go!

In [ ]:
import cv2
import time 
from keras.models import load_model
import numpy as np

def laptop_camera_go():
    # Create instance of video capturer
    cv2.namedWindow("face detection activated")
    vc = cv2.VideoCapture(0)

    # try to get the first frame
    if vc.isOpened(): 
        rval, frame = vc.read()
    else:
        rval = False
    
    # Keep video stream open
    while rval:
        # Plot image from camera with detections marked
        cv2.imshow("face detection activated", frame)
        
        # Exit functionality - press any key to exit laptop video
        key = cv2.waitKey(20)
        if key > 0: # exit by pressing any key
            # Destroy windows 
            cv2.destroyAllWindows()
            
            for i in range (1,5):
                cv2.waitKey(1)
            return
        
        # Read next frame
        time.sleep(0.05)             # control framerate for computation - default 20 frames per sec
        rval, frame = vc.read()    
        
In [ ]:
# Load facial landmark detector model
model = load_model('my_model.h5')

# Run sunglasses painter
laptop_camera_go()